FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Problem with escaping characters in php





flatliner
hey every, erm I got a problem, with escaping characters in a litte replace function I wrote. Here is the code below. Basicly its for simleys, but I cant seem to escape the characters below

Code:
:) or :(

as these are closing brackets and php things your closing somthing. here is my function code.

Code:
function emo($text){

$patterns = array('/:D/','/:L/','/:)/','/:(/','/:O/','/;)/','/:p/');

$replacements = array('<img src="images/emo/smiley_big_grin.gif" width="15" height="15" alt="" border="0">','<img src="images/emo/smiley_laugh.gif" width="15" height="15" alt="" border="0">','<img src="images/emo/smiley.gif" width="15" height="15" alt="" border="0">',
'<img src="images/emo/smiley_sad.gif" width="15" height="15" alt="" border="0">','<img src="images/emo/smiley_ohmygod.gif" width="15" height="15" alt="" border="0">','<img src="images/emo/smiley_wink.gif" width="15" height="15" alt="" border="0">','<img src="images/emo/smiley_toungeout.gif" width="15" height="15" alt="" border="0">');   

$text = preg_replace($patterns, $replacements, $text);
return $text;
};


any idea's? I have googled this alot but can find anything helpful
Flakky
EDIT: Oops, not working Sad

You might want to try to use preg_replace for each smiley instead of an array.
MrBlueSky
Use a backslash to escape special characters like '(' and ')":

Code:

$patterns = array('/:D/','/:L/','/:\)/','/:\(/','/:O/','/;\)/','/:p/');
flatliner
MrBlueSky wrote:
Use a backslash to escape special characters like '(' and ')":

Code:

$patterns = array('/:D/','/:L/','/:\)/','/:\(/','/:O/','/;\)/','/:p/');


Thanks very much, it was so simple and all, I spent ages trying all different backslash and single quotes and putting them in strings and all it took was that ha :L , thanks again Very Happy
Related topics
problem with a php randomizer script
A php problem
my website won't display... problem with index.php
Php and Other Wonderful Newbie Stories for Help.
php can't connect to mysql
SOLVED::PHP upload_max_filesize
All Joomla Related Topics
Help needed with images in php include files
Just one thing
Putting something on every page...
Direct Admin problem
Jaki portal php polecacie?
Servers are soooooo slow
LOOKING FOR THE SERVICES OF WEBSITE DESIGNERS
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.