3v4l.org

run code in 300+ PHP versions simultaneously
<?php function a($string, $length) { $string = substr($string, 0, $length); $string = substr($string, 0, strrpos($string, ' ')); return $string; } function b($string, $length) { $words = explode(' ', $string); $string = array_reduce($words, function ($current, $item) use ($length) { return mb_strlen($current) > $length ? $current : "$current$item "; }, ''); return $string; } $length = 40; $string = 'The fox flew over the moon. The cow did a big twist into the pool.'; var_dump(a($string, $length)); var_dump(b($string, $length));
Output for git.master, git.master_jit, rfc.property-hooks
string(39) "The fox flew over the moon. The cow did" string(42) "The fox flew over the moon. The cow did a "

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.5 ms | 405 KiB | 5 Q