The javascript charAt equivalent in php of felipe has a little bug. It's necessary to compare the type (implicit) aswell or the function returns a wrong result:
<?php
function charAt($str,$pos) {
return (substr($str,$pos,1) !== false) ? substr($str,$pos,1) : -1;
}
?>