3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "i want to convert this string to the following"; echo preg_replace_callback('/\b\w(?:\w{1,2}\b)?/', fn($m) => strtoupper($m[0]), $string);

preferences:
23.63 ms | 405 KiB | 5 Q