Link to home
Start Free TrialLog in
Avatar of VBTom
VBTom

asked on

Regular expression woes

I want to find every occurance of a string and be able to replace it with a different string depending on a parameter passed.  (Cryptic, I know)

<mytag=some parameter>stuff inside!</mytag> text inbetween <mytag=param again>more stuff even</mytag>

The problem I am having is that my code will give me "stuff inside!</mytag> text inbetween <mytag=param again>more stuff even" instead of each one seperately.

Here is my code:

$regexp="\[mytag\=([a-zA-Z0-9 ]+)\]([[:graph:] ]+)\[\/mytag\]";
while(eregi($regexp,$message,$regs)){
  if(str_replace(" ","",strtolower("Tom Apps com"))==str_replace(" ","",strtolower($regs[1]))){
    $message=eregi_replace($regexp,"\\2",$message);
  }else{
    $message=eregi_replace($regexp,"",$message);
  }
}
echo $message;

Help if you can! :)
ASKER CERTIFIED SOLUTION
Avatar of andreif
andreif
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial