Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 957727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:45:09+00:00 2026-05-16T00:45:09+00:00

How should parse with PHP (simple html dom/etc..) background and other images of webpage?

  • 0

How should parse with PHP (simple html dom/etc..) background and other images of webpage?

case 1: inline css

<div id="id100" style="background:url(/mycar1.jpg)"></div>

case 2: css inside html page

<div id="id100"></div>

<style type="text/css">
#id100{
background:url(/mycar1.jpg);
}
</style>

case 3: separate css file

<div id="id100" style="background:url(/mycar1.jpg);"></div>

external.css

#id100{
background:url(/mycar1.jpg);
}

case 4: image inside img tag

solution to case 4 as he appears in php simple html dom parser:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';

Please help me to parse case 1,2,3.

If exist more cases please write them, with soltion if you can please.

Thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:45:10+00:00Added an answer on May 16, 2026 at 12:45 am

    For Case 1:

    // Create DOM from URL or file 
    $html = file_get_html('http://www.google.com/');
    
    // Get the style attribute for the item
    $style = $html->getElementById("id100")->getAttribute('style');
    
    // $style = background:url(/mycar1.jpg)
    // You would now need to put it into a css parser or do some regular expression magic to get the values you need.
    

    For Case 2/3:

    // Create DOM from URL or file
    $html = file_get_html('http://www.google.com/');
    
    // Get the Style element
    $style = $html->find('head',0)->find('style');
    
    // $style now contains an array of style elements within the head. You will need to work out using attribute selectors what whether an element has a src attribute, if it does download the external css file and parse (using a css parser), if it doesnt then pass the innertext to the css parser.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP:: How can be taken charset value of webpage with simple html dom parser
Should developers avoid using continue in C# or its equivalent in other languages to
Should be available to non-U.S. companies, easy to setup, reliable, cheap, customizable, etc. What
I have created a very simple markup parser in php. However, it currently uses
I'm looking for a simple PHP library that helps filter XSS vulnerabilities in PHP
If we've learned anything from HTML/CSS it's that, declarative languages (like XML) do a
I want to parse with XmlSlurper a HTML document which I read using HTTPBuilder.
Should I start with Django or JavaScript?
Should the folders in a solution match the namespace? In one of my teams
Should you set all the objects to null ( Nothing in VB.NET) once you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.