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