Re: including an HTML file
| From: | Gaetano Savoca | Date: | Fri, 14 Jan 2005 00:53:04 +0000 |
| Subject: | Re: including an HTML file | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-25323@lists.php.net to get a copy of this message | ||
On Friday, January 14, 2005 1:06 AM [GMT+1=CET],
Gaetano Savoca <gaetanosavoca@inwind.it> ha scritto:
So i must do all manually i write thiswhere $corpo is a variable for the name of the file. if the file not existe the page have a blank body Thanks _________________________________ Gaetano Savoca http://gsweb.altervista.org On Thursday, January 13, 2005 11:16 PM [GMT+1=CET], Leif Gregory <Leifg@doh.state.nm.us> ha scritto:<?php if(file_exists($corpo)){// controll for the file //Creating the filehandle for our input file $fh=fopen("$corpo", "r");//Seeding the while loop below with the first line of theinput file$line=fgets($fh); while (!feof($fh)){ //Once we hit the <BODY> tag, start echoing out linesuntil we hit </BODY>if (preg_match("/<BODY/i", $line)){ while (!preg_match("/<\/BODY/i", $line =fgets($fh))) echo $line;} $line = fgets($fh); } fclose ($fh); }
Hello Gaetano, Thursday, January 13, 2005, 11:56:41 AM, you wrote:How i can include in a HTML (with .php extension) file another HTML file, i mean not all teh page but only the element of the <BODY> tag?I would to include with the include (nomefile); the body of other pageThere are some php function or some other way to do this?Uhmmm.. Lesse. I did something similar to this when I wrote some code to give me the headers from webservers. I had to use regexps to do it. Basically you could do something like this: <?php //Creating the filehandle for our input file $fh=fopen("myIncludeFile.html", "r"); //Seeding the while loop below with the first line of the input file $line=fgets($fh); while (!feof($fh)) { $line = fgets($fh); //Once we hit the <BODY> tag, start echoing out lines until we hit </BODY> if (preg_match("/<BODY/i", $line)) {while (!preg_match("/<\/BODY/i", $line)) { echo $line; $line = fgets($fh); }} else {$line = fgets($fh);} } fclose ($fh);I didn't actually test this, but it should work. I just took some odds and ends pieces from something else I wrote that was similar. There's room for improvement. Like right now it'll continue processing the outer while loop after the </BODY> but since </HTML> usually follows on the next line I didn't think it too inefficient. You could make the outer while stop by ANDing with the condition of the inner while loop. As always... There's going to be other ways to do this. Some of them are probably a heck of a lot better than mine.