Chetan Naik
Chetan Naik

Reputation: 151

How to str_replace \ symbol in php

I have a string containing '\' in it but when i replaced the string with blank it showing error.

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

Thank you all

Upvotes: 0

Views: 2149

Answers (4)

Dave
Dave

Reputation: 3091

try this, use \/

$emailbody = str_replace('\/','',$emailbody);

Upvotes: 0

Passionate Coder
Passionate Coder

Reputation: 7294

Try stripslashes for this

 $emailbody = "hello \ its a testing\ string";
 echo $emailbody = stripslashes($emailbody);

Note that stripslashes only remove backslashes not forward

Or

echo $emailbody =  str_replace("\\","",$emailbody);

Output

hello its a testing string

Upvotes: 1

Noman
Noman

Reputation: 1487

Here you go:

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

Upvotes: 1

A. L
A. L

Reputation: 12649

Escape your backslash so... \\

Upvotes: 0

Related Questions