the if command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

the if command

Post 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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Code: Select all

str_replace("SMILIE", "<img src="http://url.to/image.jpg" border=0>", $message);
Changing the variables inside, respectively.
Image Image
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

thanx, ill try that
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

:( that didnt work :(

anyone else got any suggestions?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

"Didn't work" doesn't help ;)
Got some code to show?
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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);
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

the image isnt showing now
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

it shows a blank box with a red cross in it, but i have checked the source of the images
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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?
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post 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
Post Reply