// Here is function that allows you to preg_match_all array of patters
function getMatches($pattern, $subject) {
$matches = array();
if (is_array($pattern)) {
foreach ($pattern as $p) {
$m = getMatches($p, $subject);
foreach ($m as $key => $match) {
if (isset($matches[$key])) {
$matches[$key] = array_merge($matches[$key], $m[$key]);
} else {
$matches[$key] = $m[$key];
}
}
}
} else {
preg_match_all($pattern, $subject, $matches);
}
return $matches;
}
$patterns = array(
'/(.*?)/',
'/(.*?)/'
);
$html = 'some text';
$html .= 'some text in another span';
$html .= 'here is the link';
$html .= '
address is here';$html .= 'here is one more span';
$matches = getMatches($patterns, $html);
print_r($matches); // result is below
/*
Array
(
[0] => Array
(
[0] => some text
[1] => some text in another span
[2] => here is one more span
[3] => here is the link
)
[1] => Array
(
[0] => some text
[1] => some text in another span
[2] => here is one more span
[3] => here is the link
)
)
*/