Welcome to WebmasterWorld Guest from 54.211.101.8

Forum Moderators: coopster & jatar k

Extracting parts of an html page

simple but I have no clue

   
11:06 pm on Nov 21, 2003 (gmt 0)

10+ Year Member



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!

12:14 am on Nov 22, 2003 (gmt 0)

10+ Year Member



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");
if(!feof($fp)){
$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;
}
}
fclose($fp);

12:16 am on Nov 22, 2003 (gmt 0)

10+ Year Member



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

while(!feof($fp)){

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

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month