Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing in php

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

Trying something witch should be simple.

I have a string witch contains a ,
and i want to replace it with ','
echo preg_replace($patterns, $replacements, $string);

echo preg_replace(,, ',', $string);

but I'm running into problems with the, can't get the replacement done.

Regards
LHG
 
Just to get this straight, you want to replace a comma [red],[/red] with a comma between a couple of quotation marks [blue]'[/blue][red],[/red][blue]'[/blue]?

Your call is wrong because the parameters need to be strings, so by nature the need to be surrounded by quotation marks, either single or double. Second that replacement really does not require a regular expression match to warrant the use of preg_replace, a simple and direct str_replace is enough, so what you really would want to do is:
Code:
[green]str_replace([/green][red]"[/red][COLOR=blue yellow],[/color][red]"[/red][green],[/green][red]"[/red][blue]','[/blue][red]"[/red][green],$string);[/green]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Exelent and it was just what I was looking for.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top