Page 1 of 1

arrays and parenthesis

Posted: Thu Apr 07, 2005 4:11 am
by s.dot
how can I use a parenthesis in an array?

I tried using this:

Code: Select all

$lp = "(";
$rp = ")";

$smiliesarray = array(":-$rp");
$imgarray = array("<img src=smilies/smil.gif");

str_replace($smiliesarray, $imgarray, $message);
the message still comes out on the users end as ": )" instead of the image. Probably because I am using htmlentities() on the message string.

So, I tried this.

Code: Select all

$lp = "&41;";
$rp = "&42;";

// same code here as above
that throws me out an error

I know my arrays are correct, and this does work because simple smilies like ":s" show up as the image.

how can I have parenthesis in my arrays without them messing up the array/or coming out as plain text when I try to str_replace them with an image?


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Apr 07, 2005 4:33 am
by Chris Corbyn
I dont get ya.... why can you use a normal parens in an array?

Code: Select all

$newarray = array('(Brackets)', 'This is good (very good)');
So long as they are quoted it's fine....

If you really must use enities then decode them with html_entity_decode() when you take thewm back out of the array.... :wink:

Posted: Thu Apr 07, 2005 5:45 am
by CoderGoblin
Your code should work as expected, (entity modification should affect it) apart from "str_replace" returns the modifies string. It does not update the current string so...

Code: Select all

$smiliesarray = array(":-)");
$imgarray = array('<img src="smilies/smil.gif">');
 
$message=str_replace($smiliesarray, $imgarray, $message);
should work

Posted: Thu Apr 07, 2005 2:02 pm
by s.dot
okay, I think I was just thrown off because the text editor I am using color codes the PHP and having :-) inside of an array throws the colors all off.