- var_dump: documentation ( source)
- var_export: documentation ( source)
- sprintf: documentation ( source)
<?php
$input = '';
$code = '';
for ($i = 0; isset($input[$i]); $i++) {
$code .= $code ? '.' : '';
$code .= sprintf('(function($str, $pos) { $length = (function($str) { for ($l = 0; isset($str[$l]); $l++) {} return $l - 1; })($str); return $str[$length - $pos]; })(%s, %u)', var_export($input, true), $i);
}
$code = sprintf('return %s;', $code);
var_dump($code);
var_dump(eval($code));