3v4l.org

run code in 300+ PHP versions simultaneously
<?php function token($word, array $listconjunctions=['and', 'on', 'in', 'or', 'which']) { return str_replace($listconjunctions,'',$word); } function token1($word, array $listconjunctions=['and', 'on', 'in', 'or', 'which']) { $listconjunctions = array_map('preg_quote', $listconjunctions); $pattern = [ '~\b('.implode('|',$listconjunctions).')\b~i', //words '~\s+~', //run on spaces '~\s+([^\w]+)$~' //spaces before punctuation, at the end of line ]; return preg_replace($pattern, [' ', ' ', '$1'], $word); } $string = "this that and on and on the other which."; echo token($string)."\n\n"; echo token1($string)."\n\n"; //second deveation echo token1('this that and, another one.');
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
this that the other . this that the other. this that , another one.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 this that the other . this that the other. this that , another one.

preferences:
139.01 ms | 402 KiB | 163 Q