- substr: documentation ( source)
- ltrim: documentation ( source)
- var_dump: documentation ( source)
- chr: documentation ( source)
- str_pad: documentation ( source)
- ord: documentation ( source)
<?php
function encode($to_encode){
$i=0;
$len=strlen($to_encode);
$ret='';
for($i=0;$i<$len;++$i){
$ret.=str_pad(ord($to_encode[$i]),4,"0",STR_PAD_LEFT);//4 should be enough for UTF-8, right?
}
return $ret;
}
function decode($numberstr){
$numberstr=(string)$numberstr;
$ret='';
$i=0;
$ii=0;
$len=strlen($numberstr);
$shit='';
$len2=null;
for($i=0;$i<$len;$i+=4){
$shit=ltrim(substr($numberstr,$i,4),'0');
$ret.=chr($shit[$ii]);
}
return $ret;
}
$str="the quick brown fox jumps over the lazy dog こどものじかん";
var_dump($str,encode($str),decode(encode($str)));