上下文;preg_match_all提取部分字符串的最佳模式是什么?
•从URL的file_get_contents,我得到很多东西一样<item></item>
,<url></url>
等
•我使用preg_match_all提取URL,标题等
例如:
$jStringToSubStract = '<a>stuffA</a><b>stuffB</b><url>http...</url>';
preg_match_all("#<url>(.*?)<\/url>#sx", $jStringToSubStract , $subItems, PREG_SET_ORDER);
foreach ($subItems as $subItem ) {
if (strlen ($subItem[1]) > 0) {
echo $subItem[1]; // this is returning the http... INSIDE <url></url>
}
}
但它是了大量慢 ...
preg_match_all有更快的选择来提取部分字符串吗?
他们从来没有学习:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
@JazZ:simplehtmldom并不是那么简单,是基于正则表达式(用于信息)的很大部分,并且很慢。 PHP已经构建了DOMDocument和DOMXPath类,并且还有两种处理XML(sax和XMLReader)的方法。 –
感谢您的来信@CasimiretHippolyte。删除我的评论。 – JazZ