Php li需要正则表达式吗
如何在php中获取Php li需要正则表达式吗,php,regex,html-lists,Php,Regex,Html Lists,如何在php中获取li标记之间的字符串?我试过很多php代码,但都不起作用 <li class="release"> <strong>Release info:</strong> <div> How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian </div> <div> How.to.Train.Your.Drag
li
标记之间的字符串?我试过很多php代码,但都不起作用
<li class="release">
<strong>Release info:</strong>
<div>
How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
</div>
<div>
How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
</div>
<div>
How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
</div>
</li>
发布信息:
How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
您可以试试这个
$myPattern = "/<li class=\"release\">(.*?)<\/li>/s";
$myText = '<li class="release">*</li>';
preg_match($myPattern,$myText,$match);
echo $match[1];
$myPattern=“/(.*?)/s”;
$myText=' * ;
预匹配($myPattern,$myText,$match);
echo$match[1];
您不需要正则表达式。似乎是(我从T.J.Crowder的评论中获取了URL)
使用工具解析HTML,例如:DOM库
这是一个获取所有字符串的解决方案(我假设这些是文本节点的值):
print\r($strings)代码>输出:
Array
(
[0] => Release info:
[1] => How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
[2] => How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
[3] => How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
)
强制性链接:
Array
(
[0] => Release info:
[1] => How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
[2] => How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
[3] => How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
)