Php bbCode,添加笑脸?

Php bbCode,添加笑脸?,php,mysql,pdo,Php,Mysql,Pdo,所以我试图在我的网站bbCodes中添加笑脸,但我不知道怎么做。我的数据库中有所有的smileys triggerwords和输出,以便于删除/添加smileys 下面这段代码不起任何作用。。。我没有得到一个错误,它也不会将例如:happy:替换为image happy.png error_reporting(E_ALL); ini_set('display_errors', 1); include('/var/www/files/connect.php'); $SmileysQ = $DB-&

所以我试图在我的网站bbCodes中添加笑脸,但我不知道怎么做。我的数据库中有所有的smileys triggerwords和输出,以便于删除/添加smileys

下面这段代码不起任何作用。。。我没有得到一个错误,它也不会将例如:happy:替换为image happy.png

error_reporting(E_ALL);
ini_set('display_errors', 1);
include('/var/www/files/connect.php');
$SmileysQ = $DB->query("SELECT * FROM smileys");
$SmileysQ->setFetchMode(PDO::FETCH_ASSOC);
while($Smileys = $SmileysQ->fetch()) {
$text = preg_replace ('/\''.$Smileys['trigger'].'/is', '<img src="images/smileys/'.$Smileys['output'].'.png" height="15" width="15" />', $text);
}

我做错了什么?

我认为preg\u replace的第一个参数中有一个意外的“标记”,导致它在搜索时失败:happy:not:happy:

正确的替代方案更有可能是:

$text = preg_replace ('/'.$Smileys['trigger'].'/is', '<img src="images/smileys/'.$Smileys['output'].'.png" height="15" width="15" />', $text);
例如:

$text = ":happy: this is a test!";
$code = ":happy:";
$text = preg_replace ('/'.$code.'/is', '<img src="images/smileys/happy.png" height="15" width="15" />', $text);
print $text;
/*
outputs: <img src="images/smileys/happy.png" height="15" width="15" /> this is a test!
the extra ' gave me: :happy: this is a test!
*/