- strpos: documentation ( source)
- ord: documentation ( source)
<?php
// calculate sum of ordinal values of chars
// starting from $start until the end of $str
function charsum($str, $start)
{
$sum = 0;
for ($i = $start, $max = strlen($str); $i < $max; ++$i) {
$sum += ord($str[$i]);
}
return $sum;
}
$str = 'hello world';
echo charsum($str, strpos($str, ' '));
$x = false;
echo $str[(int)$x]; // sh/b h