riverpast
03-16-2005, 03:27 PM
I am sure this code already exists somewhere on the net.
Can someone point me to some PHP function which loads another html page, parse out the header, and spit out the HTML in the middle of the main page?
Let me explain. For example, I have two pages - page1.php and page2.html.
In the middle of page1.php, I would like a little section:
<?
SpitPage("http://www.mydomain.com/page2.html");
?>
And I would like this function to put the content of page2.html in the middle of page1.
Please help.
azizny
03-16-2005, 05:26 PM
easy....
make the function which pases the url,
open the url, read it into a variable and then just use eregi replace to remove whatever you want... then just echo the rest of info.
Peace,
Roy@ENHOST
03-16-2005, 08:24 PM
<?
include_once('page2.php');
?>
Isn't that what you are looking for?
insanelymacintosh
03-16-2005, 10:28 PM
You are trying to split up the HTML code of the second page? Do you want it to remove all HTML from the second page and just leave the text? Please explain.
riverpast
03-17-2005, 01:50 PM
I don't want a simple include_once. It needs to get rid of the HTML page header, and all the other junk. It should only keep the <body> section.
Yes, I know it is not that difficult to write, but I am not that familiar with PHP, so I would rather find some existing code to do this.
mfonda
03-17-2005, 03:02 PM
You could do:
preg_match('/<body>(.*)<\/body>/smi', file_get_contents('www.example.com'), $contents);
$contents = $contents[1];
That should work, but its a real quick and dirty way of doing it. No good to use a regex for something like this, but it works, Ill post a better solution later, once Im home.
Roy@ENHOST
03-17-2005, 04:08 PM
Its quick but its not dirty,
I think it is a pretty good method.
Another more primitive way is to use EXPLODE.
<?
$content = file_get_contents('blah2.html');
$html = explode("<html>",$content );
$html = explode("</html>",$html[1] );
$html = $html[0];
?>
This is for non regex dudes though.
I rely heavily on explode before I started learning REGEX.
publicxuse
03-18-2005, 09:01 PM
Originally posted by Roy@ENHOST
<?
include_once('page2.php');
?>
Isn't that what you are looking for?
I would like do the include_once syntax but I would like to incude a .php that is not in the root directory but in a subdirectory.
Any suggestions?