Page 1 of 1

Remove backslash from string

Posted: 05 Nov 2020, 14:16
by Marius
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'.

Remove backslash from string

Posted: 05 Nov 2020, 17:00
by Admin
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