arrays and parenthesis

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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

arrays and parenthesis

Post 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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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:
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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