0
我一直在使用preg_match_all如何用php在文本中查找多个出现的标签?
$str = "
Line 1: This is a string
Line 2: [img] image_path [/img] Should not be [img] image_path2 [/img] included.
Line 3: End of test [img] image_path3 [/img] string.";
preg_match_all("~\[img](.+)\[/img]~i", $str, $m);
var_dump($m);
的一个简单的PHP例如,我想它返回
array(
[0] =>image_path
[1] =>image_path2
[2] =>image_path3
)
由于某种原因,我没有得到这个结果。
蚂蚁的想法?
* *它返回什么? – Cal 2012-04-26 16:28:42
不知道为什么你的标签用[]括起来,但如果你只是寻找PHP的HTML解析检查http://simplehtmldom.sourceforge.net为PHP。 – pdizz 2012-04-26 16:32:22
这看起来像BBCode,而不是HTML。但是也有一个PHP扩展:http://www.php.net/manual/en/function.bbcode-create.php – Cal 2012-04-26 16:33:53