- str_split: documentation ( source)
<?php
function str_reverse($string) {
if (! is_string ( $string )) {
exit ( 'not string' );
}
$length = strlen ( $string );
$str_array = str_split ( $string );
$str_reverse = '';
for($i = $length - 1; $i >= 0; $i --) {
$str_reverse .= $str_array [$i];
}
echo $str_reverse;
}
$str = 'abcdef ss ';
echo str_reverse ( $str );