0

我想[img]src[/img]<img src="src" alt="src" >正则表达式更改。

我发现了一些转换<img src="">[img][/img]但不是我的情况的示例。

谢谢!

4

3 回答 3

0

我相信这篇文章会帮助你解决你的问题......

http://thesinkfiles.hubpages.com/hub/Regex-for-BBCode-in-PHP

function parseCode($txt)
{
   // these functions will clean the code first
   $ret = strip_tags($txt);

   // code replacements
   $ret = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $ret);
   $ret = preg_replace('#\[link\=(.+)\](.+)\[\/link\]#iUs', '<a href="$1">$2</a>', $ret);
   $ret = preg_replace('#\[img\](.+)\[\/img\]#iUs', '<img src="$1" alt="Image" />', $ret); 
   $ret = preg_replace('#\[quote\=(.+)\](.+)\[\/quote]#iUs', '<div class="quote">$2</div><div class="quote-by">By: $1</div>', $ret);


   // return parsed string
   return $ret;
}
于 2013-02-07T13:13:21.317 回答
0
$ret = preg_replace('#\[img\](.+)\[\/img\]#iUs', '<img src="$1" alt="img">', $ret);

但一般来说,您需要一个专用的 phpBB 脚本或 phpBB 类。甚至 PHP 本身也有 BBCode 文本处理器:http ://www.php.net/manual/en/book.bbcode.php

于 2013-02-07T13:08:15.360 回答
0

你可以测试一下

 $str= preg_replace('~\[img\](.*)\[\/img\]~si', '<img src="$1" alt="$1">', $str);
于 2013-02-07T13:10:48.540 回答