Reputation: 1531
anybody know how can I replace \
by \\
?
input string : Télephone dsadad;'''´ ''''aa\
php> $in = "Télephone dsadad;'''´ ''''aa\";
... echo str_replace("\\","\\\\",$in);
Multiline input has no syntactic completion:
PHP Parse error: syntax error, unexpected T_NS_SEPARATOR in Command line code on line 2
thanks
Upvotes: 1
Views: 2798
Reputation: 55720
If you just want to do string replaces:
preg_replace("\\", "\\\\", $string);
Notice that the \
is a special character and has to be escaped!
However, if you're interested in escaping strings, PHP has some built-in functions to do that:
See the addslashes function:
addslashes($string);
Upvotes: 0
Reputation: 324640
Um... Same as any other string?
$out = str_replace("\\","\\\\",$in);
The only difference is that you have to escape each \
in the string.
Upvotes: 3
Reputation: 785146
Use str_replace:
str_replace('/', '//', 'abc/def/xyz');
OUTPUT:
abc//def//xyz
Upvotes: 2