-4

HTML Code

<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: center;">
<img border="0" height="355" src="http://i.imgur.com/8OplH.png" width="728">
</div>

I Need a img link

http://i.imgur.com/8OplH.png

but not workinkg preg_match method

#<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: center;"><img.*?>#

i need a img src but one function

thanks...

user3214838
  • 23
  • 1
  • 3
  • 1
    Unless this html is stored in a variable, you need javascript to do that. – Sterling Archer Aug 31 '13 at 01:29
  • Using regex to parse HTML is generally a bad idea. Use a framework that parses HTML, preferably with xpath support. – Tseng Aug 31 '13 at 01:44
  • **Don't use regular expressions to parse HTML. Use a proper HTML parsing module.** You cannot reliably parse HTML with regular expressions, and you will face sorrow and frustration down the road. As soon as the HTML changes from your expectations, your code will be broken. See http://htmlparsing.com/php or [this SO thread](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) for examples of how to properly parse HTML with PHP modules that have already been written, tested and debugged. – Andy Lester Aug 31 '13 at 01:45

1 Answers1

1

try

<img.*src="([^"]+)

Rgex101 DEMO

But as guys said above, it's a bad idea to parse html with regex. I personally use PHP Simple HTML DOM Parser

Enissay
  • 4,969
  • 3
  • 29
  • 56