the if command
Moderator: General Moderators
the if command
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
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
Code: Select all
str_replace("SMILIE", "<img src="http://url.to/image.jpg" border=0>", $message);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');
?>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);
So you'd need to do :
$message = str_replace("wink", "<img src=images/icon_wink.jpg border=0>", $message);
