3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "This is a " . str_repeat("test", 2) . "!\n" . str_repeat("hello", 3) . " and Bye!\n" . "When I sleep, the thought bubble says " . str_repeat("zz", 3) . "."; function str_shrink($string, $needles) { $needles = array_map(function($needle) { return preg_quote($needle, '~'); }, $needles); return preg_replace_callback( '~\b(' . implode('|', $needles) . ')\1+\b~', function($m) { return "[{$m[1]}](" . (strlen($m[0]) / strlen($m[1])) . ")"; }, $string ); } echo str_shrink($string, ['test', 'hello']);
Output for git.master, git.master_jit, rfc.property-hooks
This is a [test](2)! [hello](3) and Bye! When I sleep, the thought bubble says zzzzzz.

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