3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function check_plain($text) { return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); } $str = '<strong>foobar</strong>'; print strlen($str) . "\n"; $maxlength = 4; $cutlength = $maxlength; while (0 < $delta = strlen(check_plain(substr($str, 0, $cutlength))) - $maxlength) { print "\nDELTA: " . $delta . "\n"; $cutlength += $delta; } print "\nEND DELTA: " . $delta . "\n"; print substr($str, 0, $cutlength);