preg_replace question

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-21-2004
leegold2
 
Posts: n/a
Default preg_replace question

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

This does not replace commas with spaces. What am I doing wrong?
Thanks,
Lee G.
Reply With Quote
  #2 (permalink)  
Old 10-21-2004
Michael Fesser
 
Posts: n/a
Default Re: preg_replace question

.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
Reply With Quote
  #3 (permalink)  
Old 10-21-2004
leegold2
 
Posts: n/a
Default Re: preg_replace question

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

Reply With Quote
  #4 (permalink)  
Old 10-21-2004
Daedalus
 
Posts: n/a
Default Re: preg_replace question

> > 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


Reply With Quote
  #5 (permalink)  
Old 10-21-2004
Michael Fesser
 
Posts: n/a
Default Re: preg_replace question

.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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0