当我运行解析时,它会破坏图像,通过Oembed系统用链接替换URL。我如何编辑这个Regex,使它不会捕获BBCode括号内的链接?
// Parse bbcodes before link parsing for image support
$text = self::parseBBCodes($text);
$text = preg_replace_callback('/(https?:\/\/.*?)(\s|$)/i', function ($match) use (&$oembedCount, &$maxOembedCount) {我已经试过了
$text = preg_replace_callback('/(?<!\])(https?:\/\/.*?)(\s|$)(?!\[)/i', function ($match) use (&$oembedCount, &$maxOembedCount) {这似乎很有效,但图像并不能转化。虽然普通的bbcode是。
BBCode函数
/**
* Parse BBCode
*
* @param string $text contains the text with BBCode to be parsed
*/
public static function parseBBcodes($text)
{
// BBcode array
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[quote\](.*?)\[/quote\]~s',
'~\[size=(.*?)\](.*?)\[/size\]~s',
'~\[color=(.*?)\](.*?)\[/color\]~s',
'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s'
);
// HTML tags to replace BBcode
$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<pre>$1</'.'pre>',
'<span style="font-size:$1px;">$2</span>',
'<span style="color:$1;">$2</span>',
'<img src="$1" alt="" />'
);
// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}发布于 2015-02-10 13:06:21
你可能想摘掉你的短信
$text= strip_tags($text);https://stackoverflow.com/questions/27829346
复制相似问题