Php – Octal to sign in string from array


I want to convert octal sign like \46 to normal sign like &.
The problem is that the input is created with preg_match_all(), put into an array and then retrieved.

If I'd manually input the \46 octal notation into variable with double quotes, like
then PHP would convert it nicely.

But when I have it into an array from preg_match_all(), it returns it unconverted.

I want to convert it because I want to query database (mysql) that have records with "&" sign as ampersand.

Best Solution

Use stripcslashes()

From the stripcslashes documentation:

string stripcslashes ( string $str )
Returns a string with backslashes stripped off.
Recognizes C-like \n, \r ..., octal and hexadecimal representation.

$a = 'a \046 b \075 c';
$b = stripcslashes($a);
echo "$a ==> $b";

outputs: a \046 b \075 c ==> a & b = c