试试看:
<?php
$lines = array(
'<img src="images/online-chat.jpg" alt="Title Loans Antelope Valley - Online Chat 1"/>',
'<img src="images/online-chat.jpg" alt="Title Loans Antelope Valley - Online Chat 2"/>',
'<img src="images/online-chat.jpg" alt="Title Loans Antelope Valley - Online Chat 3"/>',
'<img src="images/online-chat.jpg" alt="Title Loans Antelope Valley - Online Chat 4"/>',
'<img src="images/online-chat.jpg" alt="Title Loans Antelope Valley - Online Chat 5"/>'
);
$alt_array = array();
foreach($lines as $line) {
$alt_array[] = getSubstring($line, 'alt="', '"');
}
print_r($alt_array);
function getSubstring($input, $start, $end)
{
preg_match("~".preg_quote($start)."(.*?)".preg_quote($end)."~", $input, $output);
return $output[1];
}
?>
输出:
Array
(
[0] => Title Loans Antelope Valley - Online Chat 1
[1] => Title Loans Antelope Valley - Online Chat 2
[2] => Title Loans Antelope Valley - Online Chat 3
[3] => Title Loans Antelope Valley - Online Chat 4
[4] => Title Loans Antelope Valley - Online Chat 5
)