I have the following text
$text = "\\vct=140\\Araignée du soir espoir,araignée du matin,espoir du matin."
I want to remove the escape characters using php..I do not want to use stripslashes since it is server dependent..
I want to remove the '\' before the '\vct=140' and the '\' before '\Arai....' How can I remove them from the string?
We have given a string and we need to remove special characters from string str in PHP, for this, we have the following methods in PHP: Using str_replace() Method: The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).
To ignoring escape sequences in the string, we make the string as "raw string" by placing "r" before the string. "raw string" prints as it assigned to the string.
The str_replace() function replaces some characters with some other characters in a string. This function works by the following rules: If the string to be searched is an array, it returns an array. If the string to be searched is an array, find and replace is performed with every array element.
Widely used Escape Sequences in PHP\' – To escape ' within the single-quoted string. \” – To escape “ within the double-quoted string. \\ – To escape the backslash. \$ – To escape $.
As far as I can tell stripslashes
works as per the manual:
<?php
$string = '\\\\vct=140\\\\Araignée du soir espoir.';
echo $string, "\n";
echo stripslashes($string), "\n";
Which outputs:
\\vct=140\\Araignée du soir espoir.
\vct=140\Araignée du soir espoir.
Sequence \\
is in list of escape sequences for special characters so you got to escape slashes twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With