PHP: Extract IMG tags from HTML pages

Hi All,

Does anyone know how i can extract IMG info from 200 html files?

Sample output below;

<img title="My title 1" src="title1.gif" alt="title 1" style="border: 0px solid ; width: 740px; height: 80px;" />
<img title="My title 2" src="title2.gif" alt="title 2" style="border: 0px solid ; width: 740px; height: 80px;" />
<img title="My title 3" src="title3.gif" alt="title 3" style="border: 0px solid ; width: 740px; height: 80px;" />
<img title="My title 4" src="title4.gif" alt="title 4" style="border: 0px solid ; width: 740px; height: 80px;" />

Thanks in adv
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could write a pHp dom parser (or find one on google) and then use XPath to extract the required images.

for more information about domparsing with xpath you can check out
detox1978Author Commented:
Thanks for the links.

Leakim, i saw that post but it doesn't really do anything strip_html can't do.

PatrickAdrichem, need a bit more help than that.  i was looking to use the gethtml and strip_html on a loop.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

detox1978Author Commented:
sorry strip_tags
How about this?


$oDocument = new DOMDocument();

$oXpathDocument = new DOMXPath($oDocument);

foreach ($oXpathDocument->query("//img") as $oImage)

	// more about $oImage

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
detox1978Author Commented:
I get the following error.

Fatal error: Class 'DOMDocument' not found
detox1978Author Commented:
I have root access and the server is CentOS with yum, in case i need to install something?
I've googled this for you, did not know it myself eather, but apperently you need the PHP-XML library installed. At our office all PHP-*'s are installed automatically so i didn't know it was a separate library
detox1978Author Commented:
I'll look into it this evening.
detox1978Author Commented:
Thanks, i've installed php-xml via "yum install php-xml" and the script now works.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.