3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ 'StackOverFlow is the best site ever', // 22 ----------------^ 'http://stackoverflow.com is the best site ever', // 22 ----------------^ 'Short string', // no ellipsis needed ^ 'pneumonoultramicroscopicsilicovolcanoconiosis', // breakpoint between ^ letters ]; function word_wrap_custom($string, $limit) { $oneWord = explode(' ', $string); if(count($oneWord) < 2 ) return $oneWord[0]; $string = substr($string, 0, $limit + 2); $endchar = substr($string, $limit, $limit + 1); $postendchar = substr($string, $limit + 1, $limit + 2); $arrAccetpEndChar = array(' ', '!', '?', ',', '.', ';', ':'); if(in_array($postendchar, $arrAccetpEndChar) || in_array($endchar, $arrAccetpEndChar)) { return $string; } else { return preg_replace('/[A-Za-z0-9]+$/', '', $string); } } foreach ($strings as $string) { var_export( word_wrap_custom($string, 22) ); echo "\n"; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
'StackOverFlow is the ' 'http://stackoverflow.' 'Short ' 'pneumonoultramicroscopicsilicovolcanoconiosis'
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
166.76 ms | 407 KiB | 5 Q