简体   繁体   中英

Replace character with special characters

I have something like this :

$x = "#frac {2} {3}";

I try this code but is doesnt work:

$x = str_replace("#","\"",$x);

I want to replace # with with \\ in this string. But I cant use str_replace.

any help?

You are replacing the # with a "
To use the backslash in a string you need to escape it.
How do you make a string in PHP with a backslash in it?

$x = "#frac {2} {3}";
$x = str_replace("#", "\\", $x);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM