Remove backslash from string
Discuss coding issues, and scripts related to PHP and MySQL.
-
Marius
- Posts:107
Remove backslash from string
How can I remove backslashes from string in php?
I tried the following code.
Code: Select all
$str ='abc-\123';
$str = stripcslashes($str);
echo $str; // abc-S
But as you can see, it returns a different result.
I tried this code with simple str_ireplace():
Code: Select all
$str ='abc-\123';
$str = str_ireplace('\', '', $str);
echo $str; // Error
But it returns:
Code: Select all
Parse error: syntax error, unexpected '', $str);
Maybe it's something simple, but, how can I remove the backslash from string in php?
From 'abc-\123' I want to get 'abc-123'.
Admin
Posts:805
You can use str_ireplace() to remove backslash from string in php, but like in the following code (add two backslashes into the removing argument):
Code: Select all
$str ='abc-\123';
$str = str_ireplace('\\', '', $str);
echo $str; // abc-123