views:

44

answers:

3

I am trying to do a simple find and replace within a string with:

$share_name = str_replace(" ", "\ ", $share_name );

Unfortunately for some reason it replaces all the spaces with "\\ " instead of "\ ". Does anybody know whats going on and how to solve this problem?

A: 

You have to escape the \ character.

$share_name = str_replace(" ", "\\ ", $share_name );
efritz
+1  A: 

I think you mean:

$share_name = str_replace(" ", "\\ ", $share_name );
killer_PL
A: 

Did you call it twice? Are you adding slashes before you echo it out or write it to the DB? Is magic_quotes on?

Your code is fine and should work. The problem is elsewhere.

Scott Saunders