php include page with div content only

I have a php page where I want to include certain div's from another page.
I know I can include the entire page, but i want to include only a certain div.
Below is an example, not of my actual use:

MainPage.php
This is the my news for today:
<?php include 'news.php #today';?>


news.php

<div id="today">Nice! I have news today</div>

<div id="other">Other divs on page I do not want to pull in<div>


I know I can do it with Jquery, but wanted to know if there is a simple way to do it with php only, no scripts.

Thanks
mewebsAsked:
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.

Ray PaseurCommented:
Any solution you find here will be a bit of a hack, and will be a fairly brittle solution if you do not control both of the pages.  If you control both MainPage and news, I would just rewrite MainPage to do the same thing that news does now.  If you do not control news the answer will depend on how news is generated, and we would need to see the actual URL for news before we could tell you a definitive answer.

A possible design would be to use file_get_contents() to read news, and then extract the DIV you want by using string manipulation functions to parse the HTML.
0
mewebsAuthor Commented:
Hi Ray

I own both pages. I am using the same information on several pages.

Some I am using bits and pieces, others I am using the entire contents.

That is why I wanted to pull specific div's from a page. I know html and jquery,
but did not know if the php include or require could work. It's simple, but pulls in
the entire page contents and does not let you pick and choose.

Thanks
0
Ray PaseurCommented:
Yes, include() will get you a lot more stuff than you might need.  But it's easy enough to write a small script that can parse that stuff and tease out just what you want.  If you can post a link to the page that has the source information I may be able to show you how to parse the document.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

mewebsAuthor Commented:
I'm working on it now. I will try to post it this evening.
0
Ray PaseurCommented:
10-4
0
COBOLdinosaurCommented:
I am assuming that the content of news is coming from a feed.  On my site I use a bunch of feeds, but instead of running them real time I just cache them and then I can mix and match to produce different combinations.  

The feeds get acquired,  parsed and formatted by CRON jobs running at intervals  ranging from 15 minutes to 24 hours depending on how frequently the target gets updated.  Then in pages I just include the already formatted feeds that I want for a particular page.

Cd&
0
mewebsAuthor Commented:
still working on code and testing to post.

this is not a news feed, I just used that as an example.

what I want is to do is include contents from certain divs on one page to another
without having to include the whole page.

page1.php [ copies data in specific div's from page2.php ]

<?php include 'page2.html #div1';?>
<?php include 'page2.html #div3';?>
<?php include 'page2.html #div5';?>


page2.php

<div id="div1">div one content</div>
<div id="div2">div two content</div>
<div id="div3">div three content</div>
<div id="div4">div four content</div>
<div id="div5">div five content</div>
<div id="div6">div six content</div>
0
Ray PaseurCommented:
If you control both pages and you're writing scripts in PHP, the data is originating somewhere and getting sent through PHP to create the HTML documents.  So you might fork the process that creates page2.php -- extract the parts of the page2 information that you want to have in page1.php, and insert those parts into page1.  This is a perfect example of why object-oriented programming is a good idea.  Each <div> can be represented a reusable object.
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
mewebsAuthor Commented:
Thanks Ray, I think that will do it.

I will get back with you.
0
mewebsAuthor Commented:
Thanks. That did it.
0
Ray PaseurCommented:
Thanks for the points.  I think that you've found the path of least resistance here!
0
mewebsAuthor Commented:
Thanks Ray. It was once I figured it out. I had to step away from it, and when I came back to it and thought about it, it clicked.
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.