This is a discussion on preg_replace question within the PHP Language forums, part of the PHP Programming Forums category; preg_replace(","," ",$kw_str2); This does not replace commas with spaces. What am I doing wrong? Thanks, Lee ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
.oO(leegold2)
>preg_replace(","," ",$kw_str2); > >This does not replace commas with spaces. What am I doing wrong? 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 |
|
|||
|
Michael Fesser wrote:
> .oO(leegold2) > > >>preg_replace(","," ",$kw_str2); >> >>This does not replace commas with spaces. What am I doing wrong? > > > 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 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. > > But str_replace() would be more efficient in this case. > > Micha |
|
|||
|
> > Possible solution: preg_replace('#,#', ' ', $kw_str2); // # = delimiter
> I have never had any luck w/this function - it does not imo work like PERL. In Perl: $kw_str2 =~ r#PATTERN#REPLACEMENT#; 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 |
|
|||
|
.oO(leegold2)
>What? Could you explain, I thought I put a regex pattern in there - >what's this delimiter requirement? http://www.php.net/manual/en/ref.pcre.php Micha |