ereg_replace help

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
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

ereg_replace help

Post by hob_goblin »

Okay, I've always been bad at reg exp's but here is my problem;

I use the code:

Code: Select all

$data = eregi_replace("\їcolor=(ї#a-fA-F0-9]{7}|їa-zA-Z]*)\](.*)\ї/color\]",
   "<span style="color:\\1;background-color:transparent">\\2</span>", $data);
so if i type in [ color=red ]something[ /color ] (wihout spaces), it will turn the text red..

but now, if i type [ color=red ] this should be red [ /color ][ color=blue ] this should be blue [ /color ] (without spaces), it all turns out red...

i know i should be changing the (.*) to somethign else, but i just can't grasp what.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

I am seriously beginning to loath regular expressions, although I use them almost everyday.
Check your meta-characters (.*) I believe you want to do (.*?) instead.
Post Reply