【发布时间】:2010-12-26 01:36:41
【问题描述】:
你好,我正在用 php 做一个解析器 正如你在下面看到的那样变换
*this* _this_ 类似于 this this
$db['profile']['information'] = str_replace( "\n" , "<br/>" , $db['profile']['information']);
$db['profile']['information'] = preg_replace('/\*([^\*]+)\*/', '<strong>\1</strong>', $db['profile']['information']);
$db['profile']['information'] = preg_replace('/_([^[_]+)_/', '<em>\1</em>', $db['profile']['information']);
$db['profile']['information'] = preg_replace('/\[img\]((?:[^\[]+|\[(?!img\]))*)\[img\]/', '<img src="\1" />', $db['profile']['information']);
问题出在 img 上。
例如我有一个 url [img]123_460217980773_23232_11_*23123*_n.jpg[img] 你知道它会解析什么。它的史诗。有人可以帮我解决吗?
感谢您花时间浏览
亚当斋月
【问题讨论】:
-
您可以从现有的PHP Markdown parser 中汲取灵感。尽管由于涵盖了各种边缘情况,因此这里的正则表达式有点复杂。