PKa
PKa

Reputation: 309

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?

Upvotes: 0

Views: 94

Answers (1)

martindilling
martindilling

Reputation: 2929

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);

Upvotes: 1

Related Questions