View Full Version : Can someone please write me this simple PHP script?
DarkTemplar194
August 11th, 2002, 22:26
Ok, all I want is for someone to write this simple script for me, as I don't know how to do it. :confused2
I'd like a script that does this:
When I type in the PHP page's HTML -
(without spaces of course)
: - ) it loads images/smiley/smile.gif
; - ) it loads images/smiley/wink.gif
: - P it loads images/smiley/tounge.gif
: - ( it loads images/smiley/sad.gif
: - D it loads images/smiley/grin.gif
I'd appreciate it if someone would write this for me between the <?php and ?> tags, nothing else. thanks in advance to whoever writes it!:biggrin2:
LaterZ
dt
keith
August 11th, 2002, 22:57
<?php
$text = str_replace(":-)", "<img src=\"images/smiley/smile.gif\" border=\"0\">", $text);
// and so on...
?>
DarkTemplar194
August 11th, 2002, 23:00
thanks, but it didn't..really work...:confused:
AH-HA, most likely cuz my host hey.nu turned off register_globals so you have to rewrite the $trings. sorry about that, it's something like HTTP_GET_VARS or somethin..:o
keith
August 11th, 2002, 23:50
must be something like that, because that code is relatively simple and should work with any normal php setup.
DarkTemplar194
August 12th, 2002, 01:28
Never mind, I got a solution elsewhere.
thanks anyway.:)
keith
August 12th, 2002, 01:44
you mean you found a host with php that works?
DarkTemplar194
August 12th, 2002, 01:46
Nah, my host was fine, and I don't think it was because of register_globals turning off; well actually it probably was :biggrin2: but someone I sorta know has been a BIG help to me lately and he wrote the script correctly for me and it worked great! :) (thanks anyway though)
keith
August 12th, 2002, 18:12
just out of curiosity, what did you end up using? i use the above code in a script i've written and it works great...
actually, i use eregi_replace(), so :p and :P , etc... both work without having to define it twice.
DarkTemplar194
August 12th, 2002, 21:24
I'm not sure if this is the best/most effecient way to write it, but this is the way it was written:
<?php
$thetext = str_replace(":-)", "<img src=\"images/smiley/smile.gif\" border=\"0\">", $thetext);
$thetext = str_replace(";-)", "<img src=\"images/smiley/wink.gif\" border=\"0\">", $thetext);
$thetext = str_replace(":-P", "<img src=\"images/smiley/tounge.gif\" border=\"0\">", $thetext);
$thetext = str_replace(":-(", "<img src=\"images/smiley/sad.gif\" border=\"0\">", $thetext);
$thetext = str_replace(":-D", "<img src=\"images/smiley/grin.gif\" border=\"0\">", $thetext);
?>
Check it out.:classic2:
Who?
August 12th, 2002, 22:18
thats the same thing that keith posted
DarkTemplar194
August 12th, 2002, 22:45
Hmm, yeah, I just noticed that. I was getting it into nuke and I guess the $text string was already taken in the php file, so they interfered. Thanks anyway though.:)
keith
August 16th, 2002, 01:33
Originally posted by Who?
thats the same thing that keith posted i was going to say... that's like 100% identical to what i wrote for you, besides replacing $text with $thetext. i just used $text as a general variable. i figured it was simple enough to figure out that it was only an example and you would obviously change the variables to suit your needs.
DarkTemplar194
August 16th, 2002, 17:33
lol, well, sorry about that. I know little to none about PHP so I didn't bother doing it.:p
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.