我想將笑臉符號轉換成圖像並鏈接到函數中的錨點 我嘗試了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中:// 請幫助 由於事先:-)
你不應該鏈接到E:\。當你把腳本放到網上時,你只能看到笑臉。你應該對你的笑臉做一個「相對鏈接」:src =「directory/smiley.jpg」 – Veda