当我运行解析时,它会破坏图像以将URL替换为通过Oembed 系统的链接。如何编辑此正则表达式,使其不会捕获 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);
}
您可能想要剥离文本
$text= strip_tags($text);