开发者

php backslash find and replace

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜