- var_dump: documentation ( source)
- preg_match_all: documentation ( source)
- implode: documentation ( source)
- str_replace: 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);
var_dump(implode(',', str_replace(array(', ', ' '), ',', $matches3[1])));