Is it possible with php to grab html information from a div based on the div id?

Is it possible with php to grab html information from a div based on the div id?
LVL 1
walker6o9Asked:
Who is Participating?
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.

Roger BaklundCommented:
Yes, that is possible. If there is no embedded div within the div you need to extract, you can use a regexp:
$str = '<div>dummy</div><div id="a">This is the content</div><div>dummy</div>';
preg_match('@<div id="a">(.*)</div>@U',$str,$matches);
$result = $matches[1];

Open in new window

0

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
Ray PaseurCommented:
Can you tell us a little about the application?  For example, are you reading the HTML from a web site from another server?
0
walker6o9Author Commented:
From the same folder off the same server.
0
Roger BaklundCommented:
Use file_get_contents() to read the data:

$str = file_get_contents('page.html');

http://php.net/manual/en/function.file-get-contents.php
0
Ray PaseurCommented:
You can use file_get_contents() to read the HTML into a variable like "$str" in the example above.  There are some DOM functions available in PHP, but if all you need is the HTML between two DIV tags, then cxr's example is likely to give you the fastest results.

Best regards, ~Ray
0
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
PHP

From novice to tech pro — start learning today.