【发布时间】:2013-05-10 11:16:07
【问题描述】:
这是字符串:
$text = "aaaaaaaa[[Image:1939.jpg||thumb|right|200px|[[1939]], [[Mr. X]] is [[here]].]]bbb";
我想要这个:
Image:1939.jpg||thumb|right|200px|[[1939]],[[Mr. X]] is [[here]].
这是一种 mediawiki 标记格式。一篇文章有一个或多个图像标记。
我的代码:
$pattern = "/\[\[Image:([\s\S]*?)\]\]/";
preg_match($pattern, $text, $match);
但我得到了
Image:1939.jpg||thumb|right|200px|[[1939
请帮忙!
【问题讨论】:
-
trim($string, '[]');:) -
您需要同时使用 ^ 标记字符串的开头和 $ 标记字符串的结尾。
-
抱歉,该字符串不是以“[[”开头并以“]]”结尾的。还有更多的字符。我已经编辑了问题。
-
你想达到什么目的?我怀疑您应该改用 MediaWiki Web API。发明自己的 MediaWiki 标记解析器绝不是一个好主意。 mediawiki.org/wiki/API:Main_page
标签: php regex preg-replace preg-match preg-match-all