Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP convert an octal characters to string

Title is pretty much self explanatory...
How do I echo an octal string ?
I tried :

<?php
echo '\047\131\145\141\162\040\072\040\047'.'<br>';
echo decoct('\047\131\145\141\162\040\072\040\047').'<br>';
echo decoct('047').decoct('131').decoct('145').decoct('141').decoct('162').decoct('040').decoct('072'),decoct('040').decoct('047').'<br>';
?>

but nothing is working for me....
I'm quite sure that some small tweak is needed here but... which one?
Thanks!

like image 316
Steven Avatar asked Dec 12 '22 02:12

Steven


2 Answers

Escape sequences are only processed inside double quoted strings, not single-quoted strings.

echo "\047\131\145\141\162\040\072\040\047".'<br>';
like image 94
Barmar Avatar answered Dec 21 '22 19:12

Barmar


This a backslash escaped string, so use stripcslashes() to un-escape, like this:

$escaped = '\047\131\145\141\162\040\072\040\047'.'<br>';
$unescaped = stripcslashes($escaped);
echo $unescaped;

Result:

'Year : '<br>
like image 23
andras.tim Avatar answered Dec 21 '22 20:12

andras.tim