我需要用微笑替换图像标签到 {smile:smilename}
<?php
$pattern = '<img src="/img/smile/(.*?).gif">';
$replacement = '{smile:$1}';
$subject = '<div contenteditable="true" id="message_text">text<img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"><img src="/img/smile/smile3.gif"></div>';
echo preg_replace($pattern, $replacement, $subject, -1 );
?>
我得到:
<div contenteditable="true" id="message_text">text<{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}><{smile:smile3}></div>
<{smile:smile3}>
但是我需要
{smile:smile3}