user1515728
user1515728

Reputation: 61

string replace function for slashes

I want to replace the string . I have used the following code to do that.

str_replace("\","/",$abc);

But it is showing error. please let me know what to do

Upvotes: 0

Views: 53

Answers (2)

David Christo
David Christo

Reputation: 876

I don't know if this holds with PHP, but with most languages, \" is an escape character - the quote won't end the string, it'll be considered part of the string.

If your trying to replace all \ with /, then the code would look something like this:

str_replace("\\", "/", $abc);

Upvotes: 2

user142162
user142162

Reputation:

You need to escape your backslash:

str_replace("\\","/",$abc);

From the documentation:

To specify a literal backslash, double it (\\).

Upvotes: 0

Related Questions