我试图从HTML文件检索链接文本。每个链接都有一个特定的类适用于他们,但网址是不同的。检索A标签之间的文本
我有以下几点:
...
<a class="fetch-me" href="products/1">Find ME!!!</a>
...
<a class="fetch-me" href="products/2">Me too!</a>
...
我用下面的PHP代码,但总是得到比我更想:
preg_match_all('<a class="fetch-me" href=".*">(.*)</a>)siU', $string, $matching_data);
不要用正则表达式解析html。如果你这样做,查克诺里斯会追捕你! http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not – johnnyArt 2010-01-09 04:22:16
这不是在Stack Overflow上的每个其他正则表达式问题的重复吗? – 2010-01-09 04:22:37
是的。而且因为有人必须这样做:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – 2010-01-09 04:23:21