preg_replace question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • leegold2

    #1

    preg_replace question

    preg_replace(", "," ",$kw_str2) ;

    This does not replace commas with spaces. What am I doing wrong?
    Thanks,
    Lee G.
  • Michael Fesser

    #2
    Re: preg_replace question

    .oO(leegold2)
    [color=blue]
    >preg_replace(" ,"," ",$kw_str2) ;
    >
    >This does not replace commas with spaces. What am I doing wrong?[/color]

    Missing delimiters, you should have received a warning (if not check
    error_reporting in your php.ini, it should be set to E_ALL).

    Possible solution: preg_replace('# ,#', ' ', $kw_str2); // # = delimiter

    But str_replace() would be more efficient in this case.

    Micha

    Comment

    • leegold2

      #3
      Re: preg_replace question

      Michael Fesser wrote:[color=blue]
      > .oO(leegold2)
      >
      >[color=green]
      >>preg_replace( ","," ",$kw_str2) ;
      >>
      >>This does not replace commas with spaces. What am I doing wrong?[/color]
      >
      >
      > Missing delimiters, you should have received a warning (if not check
      > error_reporting in your php.ini, it should be set to E_ALL).
      >
      > Possible solution: preg_replace('# ,#', ' ', $kw_str2); // # = delimiter[/color]

      What? Could you explain, I thought I put a regex pattern in there -
      what's this delimiter requirement?

      I have never had any luck w/this function - it does not imo work like PERL.



      [color=blue]
      >
      > But str_replace() would be more efficient in this case.
      >
      > Micha[/color]

      Comment

      • Daedalus

        #4
        Re: preg_replace question

        > > Possible solution: preg_replace('# ,#', ' ', $kw_str2); // # = delimiter
        [color=blue]
        > I have never had any luck w/this function - it does not imo work like[/color]
        PERL.

        In Perl:
        $kw_str2 =~ r#PATTERN#REPLA CEMENT#;

        In PHP:
        $kw_str2 = preg_replace('# PATTERN#', 'REPLACEMENT', $kw_str2);

        Where in both PATTERN is an expression and REPLACEMENT is a string

        "Perl-Compatible", not Perl.
        The reason it is called "Perl-compatible regexp" resides in the PATTERN
        part, wich use the same expression as in Perl.

        Dae


        Comment

        • Michael Fesser

          #5
          Re: preg_replace question

          .oO(leegold2)
          [color=blue]
          >What? Could you explain, I thought I put a regex pattern in there -
          >what's this delimiter requirement?[/color]



          Micha

          Comment

          Working...