By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,826 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,826 IT Pros & Developers. It's quick & easy.

preg_replace question

P: n/a
preg_replace(","," ",$kw_str2);

This does not replace commas with spaces. What am I doing wrong?
Thanks,
Lee G.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
.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
Jul 17 '05 #2

P: n/a
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

Jul 17 '05 #3

P: n/a
> > 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
Jul 17 '05 #4

P: n/a
.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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.