0

How to replace one backslash with two?
This code doesn't work:

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

PHP will two backslashes insert into database as one.
If is there one backslash it will return a parse error.

2
Contributors
6
Replies
9
Views
7 Years
Discussion Span
Last Post by kireol
0

How to replace one backslash with two?
This code doesn't work:

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

PHP will two backslashes insert into database as one.
If is there one backslash it will return a parse error.

change your double quotes " to single ticks '

0
$msg = str_replace('\','\\',$msg);

with this?


alternatively since you are escape your backslash you could use 4 \ on the second one.

0

also try

$msg = str_replace('\','\\\\',$msg);

I think that one will work. I'm drunk and no php here, but the 2nd should work

0

Not working.
When i put:

$msg = str_replace('anything','\\\\',$msg);

it works but when i put

$msg = str_replace('\','\\\\',$msg);

it doesn't work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.