3v4l.org

run code in 500+ PHP versions simultaneously
<?php function substrStrpos($text) { return substr($text, 1 + (strpos($text, ' ') ?: -1)); } function explodeSlice($text) { $explodeOnce = explode(' ', $text, 2); return array_pop($explodeOnce); } function substrStrstr($text) { return substr(strstr($text, " "), 1); } function ltrimStrstr($text) { return ltrim(strstr($text, " ")); } function pregReplace($text) { return preg_replace('~^\S+\s*~', '', $text); } $tests = [ '' => '', 'White' => '', 'White Tank' => 'Tank', 'White Tank Top' => 'Tank Top', ]; printf("| %14s| [empty] | White | White Tank | White Tank Top |\n", 'func \ tests'); $funcs = [ 'substrStrpos', 'explodeSlice', 'substrStrstr', 'ltrimStrstr', 'pregReplace', ]; foreach ($funcs as $func) { echo "------------------------------------------------------------------------\n"; printf( "| %14s| %s | %s | %s | %s |\n", $func, ...array_map( fn($result, $expected) => $result === $expected ? '✅': '💩', array_map($func, array_keys($tests)), $tests ) ); } echo "\n\n---\n"; var_export(substrStrpos('White')); echo "\n\n---\n"; var_export(explodeSlice('White'));
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
| func \ tests| [empty] | White | White Tank | White Tank Top | ------------------------------------------------------------------------ | substrStrpos| ✅ | 💩 | ✅ | ✅ | ------------------------------------------------------------------------ | explodeSlice| ✅ | 💩 | ✅ | ✅ | ------------------------------------------------------------------------ | substrStrstr| ✅ | ✅ | ✅ | ✅ | ------------------------------------------------------------------------ | ltrimStrstr| ✅ | ✅ | ✅ | ✅ | ------------------------------------------------------------------------ | pregReplace| ✅ | ✅ | ✅ | ✅ | --- 'White' --- 'White'

preferences:
56.86 ms | 1120 KiB | 4 Q