fael097
03-19-2010, 07:39 PM
hello, i have a really simple code for replacing a string message containing smilies symbols for smilies images. heres my code:
<?php
include("../connect.php");
$messagein= "smilies: =) =D =( (!)";
$smilies=mysql_query("SELECT * FROM smilies")or die(mysql_error());
while ($get=mysql_fetch_array($smilies))
{
$symbol=$get['symbol'];
$smilie=$get['url'];
$img="<img src='../shoutbox/smilies/".$smilie."' border='0' width='15' height='15'>";
$message=str_replace($symbol, $img, $messagein);
}
echo $message;
?>
as it its, with the echo outside the while loop, it will only replace one smilie, the last in the mysql smilies table.
for obvious reasons, if i put the echo inside the while loop, it will repeat the message as many times as how many smilies i have in the mysql smilies table, what i dont want, i just want the message to show once, replacing all the smilies. how to do that?!
here's a list of my available smilies http://fael097.site11.com/test/test6.php
and here's my code i posted above, as its (not)working right now http://fael097.site11.com/test/test5.php
thank you in advance
<?php
include("../connect.php");
$messagein= "smilies: =) =D =( (!)";
$smilies=mysql_query("SELECT * FROM smilies")or die(mysql_error());
while ($get=mysql_fetch_array($smilies))
{
$symbol=$get['symbol'];
$smilie=$get['url'];
$img="<img src='../shoutbox/smilies/".$smilie."' border='0' width='15' height='15'>";
$message=str_replace($symbol, $img, $messagein);
}
echo $message;
?>
as it its, with the echo outside the while loop, it will only replace one smilie, the last in the mysql smilies table.
for obvious reasons, if i put the echo inside the while loop, it will repeat the message as many times as how many smilies i have in the mysql smilies table, what i dont want, i just want the message to show once, replacing all the smilies. how to do that?!
here's a list of my available smilies http://fael097.site11.com/test/test6.php
and here's my code i posted above, as its (not)working right now http://fael097.site11.com/test/test5.php
thank you in advance