1

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..

Amarghosh
  • 58,710
  • 11
  • 92
  • 121
BobDylan
  • 15
  • 1
  • 4
  • `expression` not `expersion` in the subject.... please :( - or `regex` to save some typing and spelling pitfalls. – Peter Ajtai Jul 29 '10 at 08:19

3 Answers3

3

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');
Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44
1

look in this so answer:

How to extract img src, title and alt from html using php?

a lot of good answers !

Community
  • 1
  • 1
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
0

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
  • 100,734
  • 37
  • 191
  • 225