EDIT : now that I know better
Bu tür sorunları çözmek için regexpi kullanıyor a bad idea ve büyük olasılıkla unmaintainable ve güvenilmez kod yol açacaktır. Daha iyi bize bir HTML parser.
Solution With regexp
Bu durumda bu iki parçaya bölmek süreci daha iyidir:
- Tüm img etiketi almak
- onların meta ayıklamak
Ben bir XML ayrıştırıcı kullanamazsınız böylece doc sıkı xHTML değildir üstlenecek. ÖRN. Bu web sayfası kaynak kodu ile:
/* preg_match_all match the regexp in all the $html string and output everything as 
an array in $result. "i" option is used to make it case insensitive */
preg_match_all('/<img[^>]+>/i',$html, $result); 
print_r($result);
Array
(
    [0] => Array
        (
            [0] => <img src="/Content/Img/stackoverflow-logo-250.png" width="250" height="70" alt="logo link to homepage" />
            [1] => <img class="vote-up" src="/content/img/vote-arrow-up.png" alt="vote up" title="This was helpful (click again to undo)" />
            [2] => <img class="vote-down" src="/content/img/vote-arrow-down.png" alt="vote down" title="This was not helpful (click again to undo)" />
            [3] => <img src="http://www.gravatar.com/avatar/df299babc56f0a79678e567e87a09c31?s=32&d=identicon&r=PG" height=32 width=32 alt="gravatar image" />
            [4] => <img class="vote-up" src="/content/img/vote-arrow-up.png" alt="vote up" title="This was helpful (click again to undo)" />
[...]
        )
)
Sonra hepimiz img bir döngü ile nitelikleri olsun:
$img = array();
foreach( $result as $img_tag)
{
    preg_match_all('/(alt|title|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
}
print_r($img);
Array
(
    [<img src="/Content/Img/stackoverflow-logo-250.png" width="250" height="70" alt="logo link to homepage" />] => Array
        (
            [0] => Array
                (
                    [0] => src="/Content/Img/stackoverflow-logo-250.png"
                    [1] => alt="logo link to homepage"
                )
            [1] => Array
                (
                    [0] => src
                    [1] => alt
                )
            [2] => Array
                (
                    [0] => "/Content/Img/stackoverflow-logo-250.png"
                    [1] => "logo link to homepage"
                )
        )
    [<img class="vote-up" src="/content/img/vote-arrow-up.png" alt="vote up" title="This was helpful (click again to undo)" />] => Array
        (
            [0] => Array
                (
                    [0] => src="/content/img/vote-arrow-up.png"
                    [1] => alt="vote up"
                    [2] => title="This was helpful (click again to undo)"
                )
            [1] => Array
                (
                    [0] => src
                    [1] => alt
                    [2] => title
                )
            [2] => Array
                (
                    [0] => "/content/img/vote-arrow-up.png"
                    [1] => "vote up"
                    [2] => "This was helpful (click again to undo)"
                )
        )
    [<img class="vote-down" src="/content/img/vote-arrow-down.png" alt="vote down" title="This was not helpful (click again to undo)" />] => Array
        (
            [0] => Array
                (
                    [0] => src="/content/img/vote-arrow-down.png"
                    [1] => alt="vote down"
                    [2] => title="This was not helpful (click again to undo)"
                )
            [1] => Array
                (
                    [0] => src
                    [1] => alt
                    [2] => title
                )
            [2] => Array
                (
                    [0] => "/content/img/vote-arrow-down.png"
                    [1] => "vote down"
                    [2] => "This was not helpful (click again to undo)"
                )
        )
    [<img src="http://www.gravatar.com/avatar/df299babc56f0a79678e567e87a09c31?s=32&d=identicon&r=PG" height=32 width=32 alt="gravatar image" />] => Array
        (
            [0] => Array
                (
                    [0] => src="http://www.gravatar.com/avatar/df299babc56f0a79678e567e87a09c31?s=32&d=identicon&r=PG"
                    [1] => alt="gravatar image"
                )
            [1] => Array
                (
                    [0] => src
                    [1] => alt
                )
            [2] => Array
                (
                    [0] => "http://www.gravatar.com/avatar/df299babc56f0a79678e567e87a09c31?s=32&d=identicon&r=PG"
                    [1] => "gravatar image"
                )
        )
   [..]
        )
)
Regexplerin CPU yoğun yüzden bu sayfayı önbelleğe wan olabilir. Eğer önbellek sistemi varsa, ob_start ve yükleme / bir metin dosyasından kaydederek kullanarak kendi çimdik.
How does this stuff work ?
İlk olarak, desen eşleştirme her dize alır ve üçüncü parametre bunu çıkışına bir işlevi preg_ match_ all kullanın.
Regexp'nin:
<img[^>]+>
Biz tüm html web sayfası üzerinde uygulayın. Bu every string that start with "<img> "karakter", non içeriyor "ve a>  em> ile biter olarak okunabilir.
(alt|title|src)=("[^"]*")
Her img etiketinin üzerinde ardışık olarak uygulayın. Bu every string starting with "alt", "title" or "src", then a "=", then a ' " ', a bunch of stuff that are not ' " ' and ends with a ' " '. Isolate the sub-strings between () olarak okunabilir.
Son olarak, her şey size regexplerde ile uğraşmak istiyorum, kullanışlı hızlı bir şekilde test etmek için iyi araçlara sahip. Bu kontrol online regexp tester.
EDIT: ilk yorumuna cevap.
Ben tek tırnak kullanarak (umarım birkaç) insanlar hakkında düşünmüyordu doğrudur.
Peki, sadece kullanırsanız ', sadece tüm "ile değiştirin'.
Eğer her ikisi de katarsanız. "| Yerine ya da ('ve [^ ø] [" ^] yerine) "Birinci sonra kullanmayı deneyin, :-) kendinize tokat gerekir.