开发者

php backslash find and replace

开发者 https://www.devze.com 2023-01-08 22:17 出处:网络
I am trying to do a simple find and replace within a string with: $share_name = str_replace(\" \", \"\\ \", $share_name );

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 replace开发者_运维知识库s all the spaces with "\\ " instead of "\ ". Does anybody know whats going on and how to solve this problem?


I think you mean:

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


You have to escape the \ character.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消