0
我正在写一个ittle脚本,用对应html标签替换bbcodes。 bbcodes和html标签都存储在数据库中。这是我的[B] [/ B],但它并不适用用html标签替换bbcode
function bbcode($matches)
{
$conn = mysqli_connect('127.0.0.1','root','','esame') or die("Connection failed: " . $conn->connect_error);
foreach ($matches as $match)
{
$query = mysqli_query($conn,"SELECT html FROM `bbcode` WHERE bbcode='{$match}' ");
while ($html = mysqli_fetch_array($query,MYSQLI_ASSOC))
{
return 'Html: '.$html['html'];
}
$conn->close();
}
}
$regex = '/\[b\](.+)\[\/b\]/is';
echo '<br>'.preg_replace_callback($regex,"bbcode",$text).'<br>';
它返回某种错误的实际代码? – 2014-11-24 10:33:52
不,它只是返回输入字符串,例如[b] foo [/ b] – Antonio102 2014-11-24 10:36:09
preg_replace_callback的文档页面有一个带有bbcode函数的用户注释。也许你可以看看那个'灵感'。 ;) – GolezTrol 2014-11-24 10:45:38