3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'this! string contains, many. words but I want 5'; function get5Words(string $str) { $words = str_word_count($str, 2); $cnt = 0; foreach($words as $strPos => $v) { if($cnt++ === 5) { return substr($str, 0, $strPos-1); } } return $str; } var_dump(get5Words($str));
Output for git.master, git.master_jit, rfc.property-hooks
string(34) "this! string contains, many. words"

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:
116.04 ms | 405 KiB | 5 Q