homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Extracting parts of an html page
simple but I have no clue

10+ Year Member

Msg#: 2137 posted 11:06 pm on Nov 21, 2003 (gmt 0)

This is most likely very easy to answer for php people but I have not much of a clue, if any, about php. Basically the situation is this: I have a website in html and now want to build a second, related, one. Certain portions of the text will be identical on both sites and are quite often updated. Now, how can I make changes in the text on the first site which then automatically shows up on the second one as well? I know, I can create templates and then use include for both sites, but as the first one is already existing I would rather like to extract partions of the text there with php.

As I have full control over both sites is there a way to mark certain paragraphs in the first site, like

<!-- start -->
text text
text text
<!-- end -->

and then capture everything bewteen <!-- start --> and <!-- end --> and include on the second site?

Would be most grateful for any replies. Thanks!



10+ Year Member

Msg#: 2137 posted 12:14 am on Nov 22, 2003 (gmt 0)

I'm unable to test this right now, but here's something that should work (although I'd go through the "trouble" of copy/pasting the relevant parts to separate PHP files and including them myself):

On the second page, which copies from the first one, place this where you want the info to be copied:

$fp = fopen("firstpage.php","r");
$buffer = fgets($fp,5000);
$x = 0;
if($buffer == "<!-- start of chunk of text -->"){$x = 1;}
if($buffer == "<!-- end of chunk of text -->"){$x = 0;}
if($x == 1){
echo $buffer;


10+ Year Member

Msg#: 2137 posted 12:16 am on Nov 22, 2003 (gmt 0)

Sorry, you should change that "if" in a "while":


Also, I added some whitespace to make my code more readable, but it was apparently removed by this forum's underlying code.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved