Reputation: 1200
for example:
INPUT:
<img "img1.gif" alt="Donkey"><BR>
<img "img2.gif" alt="Horse"><BR>
<img "img3.gif" alt="Orangutan"><BR>
OUTPUT
Donkey
Horse
Orangutan
looked around for this but no cigar. Any ideas? thnx!
Upvotes: 0
Views: 2661
Reputation: 39704
for a quick solution use preg_replace()
$text = '<img img1.gif" alt="Donkey"><BR>
<img img2.gif" alt="Horse"><BR>
<img img3.gif" alt="Orangutan"><BR>';
$replace = preg_replace('/<img(.*)alt="(.*)"\>/', "$2", $text);
echo $replace;
Upvotes: 3
Reputation: 173522
Feeling generous today, here's da c0dez:
$html =<<<EOS
<img "img1.gif" alt="Donkey"><BR>
<img "img2.gif" alt="Horse"><BR>
<img "img3.gif" alt="Orangutan"><BR>
EOS;
$d = new DOMDocument;
$d->loadHTML($html);
foreach ($d->getElementsByTagName('img') as $img) {
echo $img->getAttribute('alt'), "\n";
}
Upvotes: 3
Reputation: 394
You can't have looked around a lot - look at this quite similar question:
How to extract img src, title and alt from html using php?
Upvotes: 0