Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    preg_replace (don't know how to describe it)

    Code:
    $variable["new"]="hi";
    $variable["cow"]="wow";
    $string="nice to meet you [phpfile=new]";
    $pattern='/\[phpfile=(\w+)\]/i';
    $replace=$variable["$1"];
    preg_replace($pattern,$replace,$string);

    When I tried this, it gave me an error about $1 not existing. Does anyone know how to solve this? I have also tried \\1, and tried heck alot of different things, but couldn't resolve this.

    Thanks..

    - Mike

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is $1

    php.net example
    PHP Code:
    $string 'April 15, 2003';
    $pattern '/(\w+) (\d+), (\d+)/i';
    $replacement '${1}1,$3';
    echo 
    preg_replace($pattern$replacement$string); 
    Hopefully this will help you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •