我怎么能为php创建一个preg_match_all正则表达式模式给我这个代码?
<td class="class2"> </td>
<td class="class2" align="right"><span class="DarkText">I WANT THIS TEXT</span></td>
Run Code Online (Sandbox Code Playgroud)
为了获取span类中的文本?谢谢!
可能重复:
抓取A元素的href属性
我已经浏览了很多其他帖子,看到所有帖子都遵循一些固定的Anchor标签格式.他们中的大多数人都认为锚标签格式是<a href="http://www.example.com/">Hello</a>..也许是target后面的属性<a..但我正在尝试编写一个正则表达式来匹配锚标记的href,无论它出现在标记中的哪个位置.它可以出现在alt,title,target之后或者它们之间.还有另一种情况,锚标记使用单引号而不是双引号.
我已经尝试了半个小时而没有得到任何结果.所以在这里发布.
我的一些HTML文件包含如下字符串:
{foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
Run Code Online (Sandbox Code Playgroud)
我想申请PHP's preg_match_all他们,并希望返回一个array像下面打印的好
Array
(
[0] => {foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
[1] => any_kind_of_charaters
[2] => Any kind of string including "\n\r" and spaces here
)
Run Code Online (Sandbox Code Playgroud)
这个REGEX:/\{foreach\s+\$(.*)\}\s+(.*)\s+\{\/foreach\}/对我来说还可以,
但是当我在{foreach}{/foreach}标签之间添加新行(\n)时它会失败.
非常感谢您的帮助,谢谢.
使用"S"修改器后的阵列
Array
(
[0] => {foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
[1] => any_kind_of_charaters}
Any kind of …Run Code Online (Sandbox Code Playgroud) item1<br>item2<br>item3<br>item4<br>item5
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到每个之间的文本<br>和<br>?我尝试使用preg_match_all和以下正则表达式,但它没有显示所有结果.
`<br>(.*)<br>`USI
提前致谢!
我想编写一个像这个函数(str,find){}这样的函数,这样当我有一个str之类的时候
大家好,HeLlo和hElLo大家都说
并且术语发现像"你好",我得到了结果
<span class="match">Hello</span> every body, <span class="match">HeLlo</span> and <span class="match">hElLo</span> everyone blah
Run Code Online (Sandbox Code Playgroud) 嗨,我的模式是:
'<span\s+id="bodyHolder_newstextDetail_nwstxtPicPane"><a\s+href="(.*)"\s+target="_blank"><img\s+alt="(.*)"\s+title="(.*)"\s+src=\'(.*)\'\s+/>'
Run Code Online (Sandbox Code Playgroud)
而字符串:
<div class="nwstxtpic">
<span id="bodyHolder_newstextDetail_nwstxtPicPane"><a href="xxxxx" target="_blank"><img alt="xxxxx" title="xxxxx" src='xxxxx' />
Run Code Online (Sandbox Code Playgroud)
好吧,我的用于查找和获取我在patern中定义的4个组的值的PHP代码是:
$picinfo=preg_match_all('/<span\s+id="bodyHolder_newstextDetail_nwstxtPicPane"><a\s+href="(.*)"\s+target="_blank"><img\s+alt="(.*)"\s+title="(.*)"\s+src=\'(.*)\'\s+/>/',$newscontent,$matches);
foreach ($matches[0] as $match) {
echo $match;
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何获得这4组的价值
href="(.*)"
alt="(.*)"
title="(.*)"
src=\'(.*)\'
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?谢谢.
所以我试图从一个字符串中获取所有url,其脚本如下所示:
$file = file_get_contents('something.txt');
function getUrls($string) {
preg_match_all('~href=("|\')(.*?)\1~', $string, $out);
print_r($out);
}
getUrls($file);
Run Code Online (Sandbox Code Playgroud)
本文档中包含的网址可能不完善 - 即"/blah/blah.asp?2".问题是,当我运行这个脚本时,我得到一个看起来像这样的数组:
Array
(
[0] => Array
(
[0] => href="#A"
[1] => href="#B"
[2] => href="#C"
)
[1] => Array
(
[0] => "
[1] => "
[2] => "
)
[2] => Array
(
[0] => #A
[1] => #B
[2] => #C
)
)
Run Code Online (Sandbox Code Playgroud)
知道这可能会发生什么吗?我不知道为什么它返回带有哈希符号的字母列表而不是所需的URL.我该如何回归网址呢?
我创建了一个清除已发布标题的函数.
function title_var($title_variable) {
$title_variable = mysql_real_escape_string(ucwords(strtolower(trim(htmlspecialchars($title_variable, ENT_QUOTES)))));
return stripslashes($title_variable);
}
Run Code Online (Sandbox Code Playgroud)
我现在需要能够在()或[]全部大写之间做任何事情.例如"我的公司名称(cbs)limited"或"我的公司名称[cbs] limited",变为"我的公司名称(CBS)有限公司","CBS"在所有首都.
我已经完成了将所有单词设为大写的第一部分,我只需要在括号之间进行任何设置.
我需要从字符串中删除特定的div.
我的代码是:
$varz = "<div class="post-single">
<p> Hello all! </p>
<div class="ad">I want to remove this div</div>
</div>";
$varzfinal = preg_replace('/<div class="ad">.+<\/div>/siU', '', $varz);
echo $varzfinal;
Run Code Online (Sandbox Code Playgroud)
我需要删除它: <div class="ad">I want to remove this div</div>
实现这一目标的最佳方法是什么?
我试图从这个字符串中的单词之间提取数字.
110.0046102.005699.0008103.0104....
Run Code Online (Sandbox Code Playgroud)
我想在点(点/周期)后提取4位数.
110.0046 102.0056 99.0008 103.0104 我想知道这是否可以使用正则表达式,或者我是否应该使用其他方式.