我正在尝试将笑脸符号转换为图像并将链接转换为函数中的锚点,我尝试了 10 多次解决但无法解决,我是 php 新手。
这是我的代码:
 <?php
 $text = "hey :/  Theere is 2 links andc3 smiles in this text  http://google.com   then    trun nto http://yahoo.com";
function cust_text($string)
{
$content_array = explode(" ", $string);
$output = '';
foreach($content_array as $content)
{
// check word starts with http://
if(substr($content, 0, 7) == "http://")
$content = '<a href="' . $content . '">' . $content . '</a>';
//starts word with www.
if(substr($content, 0, 4) == "www.")
$content = '<a href="http://' . $content . '">' . $content . '</a>';
$output .= " " . $content;
}
output = trim($output);
$smiles = array(':/'  => 'E:\smiles\sad.jpg');
foreach($smiles as $key => $img) {
$msg =   str_replace($key, '<img src="'.$img.'" height="18" width="18" />',       $output);}
return $msg;
}
echo cust_text($text); 
?> 
结果笑脸正在替换:/在http://请帮助提前感谢:-)