<?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));
preferences:
25.3 ms | 407 KiB | 5 Q