3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$lines = file('your_text_file.txt', FILE_IGNORE_NEW_LINES); $lines = [ '3M Company MMM', '99 Cents Only Stores NDN', 'AO Smith Corporation AOS', 'Aaron\'s, Inc. AAN', ]; foreach ($lines as $line) { [$names[], $symbols[]] = preg_split('~\s+(?=[A-Z]+$)~m', $line); } var_export($names); echo "\n---\n"; var_export($symbols); unset($names, $symbols); echo "\n***\n"; //$text = file_get_contents('your_text_file.txt'); $text = <<<TEXT 3M Company MMM 99 Cents Only Stores NDN AO Smith Corporation AOS Aaron's, Inc. AAN TEXT; preg_match_all('~(.+?)\s+([A-Z]+)$~m', $text, $matches, PREG_SET_ORDER); var_export(array_column($matches, 1)); echo "\n---\n"; var_export(array_column($matches, 2));
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => '3M Company', 1 => '99 Cents Only Stores', 2 => 'AO Smith Corporation', 3 => 'Aaron\'s, Inc.', ) --- array ( 0 => 'MMM', 1 => 'NDN', 2 => 'AOS', 3 => 'AAN', ) *** array ( 0 => '3M Company', 1 => '99 Cents Only Stores', 2 => 'AO Smith Corporation', 3 => 'Aaron\'s, Inc.', ) --- array ( 0 => 'MMM', 1 => 'NDN', 2 => 'AOS', 3 => 'AAN', )
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 array ( 0 => '3M Company', 1 => '99 Cents Only Stores', 2 => 'AO Smith Corporation', 3 => 'Aaron\'s, Inc.', ) --- array ( 0 => 'MMM', 1 => 'NDN', 2 => 'AOS', 3 => 'AAN', ) *** array ( 0 => '3M Company', 1 => '99 Cents Only Stores', 2 => 'AO Smith Corporation', 3 => 'Aaron\'s, Inc.', ) --- array ( 0 => 'MMM', 1 => 'NDN', 2 => 'AOS', 3 => 'AAN', )

preferences:
148.95 ms | 409 KiB | 5 Q