i nasıl yapabilirim php ile veritabanından görüntülemeden önce bir gülen IMG kelime :)) değiştirmek istiyorum
Bir çözüm str_replace a> işlevini kullanmak olacaktır.
Örneğin (Using ":-), "Ben senin daha çok seviyorum ki" :)) -) doğru olanı "" Sadece tat meselesi ^ ^ Up kullanmak için " em> :
$str = "This is a sentence with a smiley :-)";
$new_str = str_replace(
array(
':-)',
),
array(
'<img src="smiley.png" alt=":-)" />'
),
$str
);
echo $new_str;
Bu çıktıyı alırsınız:
This is a sentence with a smiley <img src="smiley.png" alt=":-)" />
yani gülen bir görüntü ile değiştirilmiştir.
Note that I used an array for the first and second parameter, when calling str_replace : if you have other smileys, you can just add them to those two arrays (the first array being for the "searched" string, and the second for the "replacement").
(What I mean is : no need to call str_replace birkaç zaman: bir defa, dizileri kullanarak,) birçok değiştirmeleri için yeterli olmalıdır em>
And, as a sidenote : I used the original "text" of the smiley for the alt attribute of the img tag : this way, if the image cannot be displayed, the browser will display the textual version of the smiley -- which is better than nothing.
Gibi bir şey kullanabilirsiniz:
str_replace(':))', '<img src="path to your image" title="image title" />', $string);
Birden 'suratları' değiştirmek istiyorsanız, diziler kullanın:
$find = array(
':)',
':('
);
$replace = array(
'<img src="path to happy image" title="" />',
'<img src="path to sad image" title="" />');
);
str_replace($find, $replace, $string);
Eğer aşağıdaki gibi bir şey kullanabilirsiniz. Eğer var her resim için yeni bir yedek oluşturun.
$message = str_replace(":)", "<img src='happy.png' alt=':)'/>", $message);
$message = str_replace(":(", "<img src='unhappy.png' alt=':('/>", $message);
Bu $message "I'm happy :)" "I'm happy <img src='happy.png' alt=':)'/>" dönüşecektir. Alt tag kullanıcıların görüntüleri görmüyorum orijinal suratı ortaya koymaktadır.