- array_map: documentation ( source)
- preg_match_all: documentation ( source)
- explode: documentation ( source)
- array_filter: documentation ( source)
- natsort: documentation ( source)
- array_unique: documentation ( source)
- join: documentation ( source)
<?php
$haystack3 = '<span class=\'descr\'>test, test2, test3</span>
<span class=\'descr\'>test</span>
<span class=\'descr\'>test4 test5</span>';
preg_match_all('#^<span class=\'descr\'>(.*?)</span>$#m', $haystack3, $matches3);
$data3 = explode(',', $matches3[1]);
$data3 = array_filter(array_unique(array_map('trim', $data3)));
natsort($data3);
echo '<b>' . join(', ' , $data3 ) . '</b>';
echo "<br>\n";
echo '<font color="blue">' . '<b>' . count( $data3 ) . '</b>' . '</font>' . " tags were found." . '<br>';
?>