Page 1 of 1
the if command
Posted: Fri Feb 27, 2004 9:07 am
by davy2001
i have a guestbook and a smiley system.
if a user wants a smiley to work, they click the smiley and it automatically adds the shortcut for the smiley. but thats not what im after.
i need to know that when the form is submitted, it should change the smiley shortcut into the smiley.
i need a code that does this:
if sumthing is typed, replace with emoticon
Please help
Posted: Fri Feb 27, 2004 9:16 am
by phice
Code: Select all
str_replace("SMILIE", "<img src="http://url.to/image.jpg" border=0>", $message);
Changing the variables inside, respectively.
Posted: Fri Feb 27, 2004 9:17 am
by davy2001
thanx, ill try that
Posted: Fri Feb 27, 2004 10:02 am
by davy2001

that didnt work
anyone else got any suggestions?
Posted: Fri Feb 27, 2004 10:06 am
by markl999
"Didn't work" doesn't help

Got some code to show?
Posted: Fri Feb 27, 2004 10:07 am
by davy2001
Code: Select all
<?
$name = $_POST['name'] ;
$message = $_POST['texarea'] ;
str_replace("wink", "<img src=images/icon_wink.jpg border=0>", $message);
str_replace(":D", "<img src=images/icon_biggrin.jpg border=0>", $message);
str_replace("8)", "<img src=images/icon_cool.jpg border=0>", $message);
str_replace(":(", "<img src=images/icon_cry.jpg border=0>", $message);
str_replace(":((", "<img src=images/icon_mad.jpg border=0>", $message);
str_replace(":p", "<img src=images/icon_razz.jpg border=0>", $message);
str_replace(":o", "<img src=images/icon_redface.jpg border=0>", $message);
str_replace(":R", "<img src=images/icon_rolleyes.jpg border=0>", $message);
$filename = 'guestbook.html';
$fp = fopen($filename, "a");
$string = "
<center>
<table width=482 border=2 bordercolor=#00CC00>
<tr>
<td width=472 valign=top><b>Name:</b> $name</td>
</tr>
<tr>
<td height=23 valign=top><b>Message:</b> $message</td>
</tr>
</table>
<br>
</center>";
$write = fputs($fp, $string);
fclose($fp);
header ('Location: guestbook.html');
?>
does this help?
Posted: Fri Feb 27, 2004 10:09 am
by markl999
If you look at
http://php.net/str_replace you'll see that str_replace() returns a string with the replacements.
So you'd need to do :
$message = str_replace("wink", "<img src=images/icon_wink.jpg border=0>", $message);
Posted: Fri Feb 27, 2004 10:12 am
by davy2001
the image isnt showing now
Posted: Fri Feb 27, 2004 10:14 am
by markl999
But if you view the html source, did it replace the text with the image src ok? If it did then it's just the paths to the images are incorrect, if not, then there's something else wrong.
Posted: Fri Feb 27, 2004 10:16 am
by davy2001
it shows a blank box with a red cross in it, but i have checked the source of the images
Posted: Fri Feb 27, 2004 10:16 am
by markl999
Is this online anywhere we can see it? Also if you 'view source' is the <img src ...> bit correct for each of the replacements?
Posted: Fri Feb 27, 2004 10:17 am
by davy2001
wait, nevermind
in the php i had it directing to th correct directory but it had the incorrect file extension
thank everyone for your help