How can I remove escape characters using PHP?

2019-02-22 20:38发布

问题:

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?

回答1:

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.



标签: php escaping