tags:

views:

48

answers:

3

I'm trying to learn reg exp,

i want to get title of <img only from the text

the text is differ and basically look like this

<a href="http://abcde.com" target="_blank"><img src="http://abcde.com/img/aa.jpg" title="img title" id="img id" class="img class" />

any guidance and advise are appreciated..

+3  A: 

it would be something like that:

'|<img(.*)title="(.*)"(.*)/>|Um'

but i would advise to parse html through dom (DomDocument, simplehtmldom, etc):

$doc = new DomDocument();
$doc->loadHTML($page);
$imgElement = $doc->getElementById('img id');
$title = $imgElement->getAttribute('title');
kgb
+1  A: 

look in this so answer:

http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php

a lot of good answers !

Haim Evgi
A: 

You'll get the answer "Don't use regular expressions!" But if you still want to, try:

#<img[^>]+title="([^"]*)"#

PS: This regex assumes that there is no > in any attribute before title. If this may not be assumed, say so.

nikic