1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reg Expr trouble!

Discussion in 'HTML, Graphics & Programming' started by toastyman, 26 May 2006.

  1. toastyman

    Gangster

    Joined: 30 Dec 2005

    Posts: 421

    Yup, once again i'm back with another regular expression problem.

    Code:
    preg_replace('/*php\[{$matches[$i]}\]*/','<?php '.$cur_row["code"].' ?>',$content);
    
    In theory it should replace the following string with some php code in the array $cur_row:
    *php[x]*
    ...where x is an integer in the array matches.

    When I run this code, I get this error:
    Anyone got any ideas?
     
    Last edited: 26 May 2006
  2. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 28,940

    Location: Back in East London

    you need to escape '*' as well, if you wish to use it's literal value.

    Code:
    preg_replace("/\*php\[{$matches}\]\*/", "<?php {$cur_row['code']} ?>", $content);
     
    Last edited: 26 May 2006
  3. toastyman

    Gangster

    Joined: 30 Dec 2005

    Posts: 421

    Aha that's what I missed :)

    Spot on, works a treat :D