question about str_replace function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kencana
    New Member
    • Nov 2006
    • 26

    question about str_replace function

    Hi all,

    I got a doubt about the str_replace function.

    [PHP]<?php
    $string="avenue 1, ave 1";
    $words=str_repl ace ("ave","avenue" , $string);
    echo $words;
    ?>[/PHP]

    the php code above will return me "avenuenue 1, avenue 1". i expect the result will be "avenue 1, avenue 1". any idea of how can i get such result?

    Thank you

    Regards,
    Kencana
  • kamill
    New Member
    • Dec 2006
    • 71

    #2
    try with this example....[PHP]<?php
    arr = array("avenue 1", "ave 1");
    print_r(str_rep lace("ave","ave nue",$arr,2));
    ?> [/PHP]

    Comment

    • lordspace
      New Member
      • Nov 2006
      • 10

      #3
      Hi,

      use this instead of str_replace.
      We need more complex search and replace functionality so we use PCRE (Perl Compatible Regular Expressions).

      [php]
      $words=preg_rep lace("/\bave\b/si","avenue", $string);
      [/php]

      Svet

      Comment

      Working...