Here's a quick solution, there's probably a more elegant/performant way around however.
<?php
function extractUppercase($str) {
$ret = array();
$arr = preg_split("/[\s,\.\p{P}]+/", $str);
$count = count($arr);
for ($i = 0; $i < $count; $i++) {
if ($arr[$i] == strtoupper($arr[$i]) && !empty($arr[$i]) && !is_numeric($arr[$i]))
$ret[] = $arr[$i];
}
return $ret;
}
echo "<pre>";
$test = '4. A quick and lively dance. [Obs.]
Make you dance canary With sprightly fire and motion. Shak.
CANARY
Ca*na"ry, v. i.
Defn: To perform the canary dance; to move nimbly; to caper. [Obs.]
But to jig of a tune at the tongue\'s end, canary to it with your
feet. Shak.
CANARY BIRD
Ca*na"ry bird`. (Zoöl.)
Defn: A small singing bird of the Finch family (Serinus Canarius), a
native of the Canary Islands. It was brought to Europe in the 16th
century, and made a household pet. It generally has a yellowish body
with the wings and tail greenish, but in its wild state it is more
frequently of gray or brown color. It is sometimes called canary
finch.canary.
Canary bird flower (Bot.), a climbing plant (Tropæolum peregrinum)
with canary-colored flowers of peculiar form; -- called also canary
vine.
CANASTER
Ca*nas"ter, n. Etym: [Sp. canasta, canastro, basket, fr. L.
canistrum. See Canister.]
Defn: A kind of tobacco for smoking, made of the dried leaves,
coarsely broken; -- so called from the rush baskets in which it is
packed in South America. McElrath.
CAN BUOY
Can" buoy`.
Defn: See under Buoy, n.
CANCAN
Can"can, n. Etym: [F.]
Defn: A rollicking French dance, accompanied by indecorous or
extravagant postures and gestures.
CANCEL
Can"cel, v. i. [Imp. & p. p. Canceled or Cancelled (; p. pr. & vb. n.
Canceling or Cancelling.] Etym: [L. cancellare to make like a
lattice, to strike or cross out (cf. Fr. canceller, OF. canceler) fr.
cancelli lattice, crossbars, dim. of cancer lattice; cf. Gr.
Chancel.}]';
$result = extractUppercase($test);
echo "Test:\n\n", $test, "\n\n\n\nResult:\n\n";
print_r($result);
echo "</pre>";
?>
Which leads to this sample output:
Test:
4. A quick and lively dance. [Obs.]
Make you dance canary With sprightly fire and motion. Shak.
CANARY
Ca*na"ry, v. i.
Defn: To perform the canary dance; to move nimbly; to caper. [Obs.]
But to jig of a tune at the tongue's end, canary to it with your
feet. Shak.
CANARY BIRD
Ca*na"ry bird`. (Zoöl.)
Defn: A small singing bird of the Finch family (Serinus Canarius), a
native of the Canary Islands. It was brought to Europe in the 16th
century, and made a household pet. It generally has a yellowish body
with the wings and tail greenish, but in its wild state it is more
frequently of gray or brown color. It is sometimes called canary
finch.canary.
Canary bird flower (Bot.), a climbing plant (Tropæolum peregrinum)
with canary-colored flowers of peculiar form; -- called also canary
vine.
CANASTER
Ca*nas"ter, n. Etym: [Sp. canasta, canastro, basket, fr. L.
canistrum. See Canister.]
Defn: A kind of tobacco for smoking, made of the dried leaves,
coarsely broken; -- so called from the rush baskets in which it is
packed in South America. McElrath.
CAN BUOY
Can" buoy`.
Defn: See under Buoy, n.
CANCAN
Can"can, n. Etym: [F.]
Defn: A rollicking French dance, accompanied by indecorous or
extravagant postures and gestures.
CANCEL
Can"cel, v. i. [Imp. & p. p. Canceled or Cancelled (; p. pr. & vb. n.
Canceling or Cancelling.] Etym: [L. cancellare to make like a
lattice, to strike or cross out (cf. Fr. canceller, OF. canceler) fr.
cancelli lattice, crossbars, dim. of cancer lattice; cf. Gr.
Chancel.}]
Result:
Array
(
[ 0] => A
[ 1] => CANARY
[ 2] => CANARY
[ 3] => BIRD
[ 4] => A
[ 5] => CANASTER
[ 6] => L
[ 7] => A
[ 8] => CAN
[ 9] => BUOY
[ 10] => CANCAN
[ 11] => F
[ 12] => A
[ 13] => CANCEL
[ 14] => L
[ 15] => OF
)
If it does the deed feel free to send a tip to 12VJryWvJaUNa9LWKVnY38Ds1YMqZjE8L1 otherwise this was a fun exercise