到目前,我们看看提交的表情,在Index类中的handle方法:
$data = array(
'username' => I(username),
'content' => I(content),
'time' => time()
);
p($data);
提交一个许愿,内容中加上几个表情,用firefox看看返回值:
下面把字符型表情替换成gif图片。
D:\wamp\www\wish\Common\Common\function.php
// 表情替换
function replace_phiz($content){
preg_match_all('/\[.*?\]/is', $content, $arr);
if ($arr[0]) {
$phiz = F('phiz', '', './Data/');
foreach($arr[0] as $v){
foreach($phiz as $key => $value){
if($v == '[' . $value . ']'){
$content = str_replace($v, '<img src="' . __ROOT__ . '/Public/Images/phiz/' . $key . '.gif" />' , $content);
}
continue;
}
}
}
echo $content;
};
修改handle方法:
$data = array(
'username' => I(username),
'content' => I(content),
'time' => time()
);
//p($data);
replace_phiz($data['content']);
提交许愿并观察返回值: