read html file between <body> tags
Moderator: General Moderators
read html file between <body> tags
I'm trying to find a way to rid a site of an inline frame using php.
My thought was to set up a table where the old i-frame was and have php insert the code between the <body> & </body> tags from the html file.
I'm a little stumped on how to go about reading in the file between those tags so there are not 2 headers in the resulting file. I've googled and searched the forums as much as I could, but I'm not certain I know what I'm looking for. Any help is greatly appreciated.
Justin
My thought was to set up a table where the old i-frame was and have php insert the code between the <body> & </body> tags from the html file.
I'm a little stumped on how to go about reading in the file between those tags so there are not 2 headers in the resulting file. I've googled and searched the forums as much as I could, but I'm not certain I know what I'm looking for. Any help is greatly appreciated.
Justin
one more related question. I have it working as long as my <body> tag is empty. What might I use if the tag has some peramiters in it such as:
<body class="whatever">
I think I'm looking for something like a wildcard or regular expressions that can look for the beginnig characters "<body" then any number of random alpha numeric characters up until the ">" But it's eluding me.
Thanks again for any help.
Justin
<body class="whatever">
I think I'm looking for something like a wildcard or regular expressions that can look for the beginnig characters "<body" then any number of random alpha numeric characters up until the ">" But it's eluding me.
Thanks again for any help.
Justin
Might help if I posted the code I'm using now
Code: Select all
<?php
$file=file_get_contents("tutorials/web/web_server.html", "r");
$htm=explode("<body>",$file);
$html=explode("</body>",$htm[1]);
$body=$html[0];
print "$body";
?>
Last edited by jds580s on Tue May 18, 2004 4:55 pm, edited 1 time in total.
Ahh, I see I need to re-word my issue because you answered what I asked but I didn't ask what I wanted. 
My body tag looks like this
<body leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
but it won't always have the same stuff in it.
this:
obviously returns
leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
and then the rest of the document as expected.
I'm curious if I can include all the characters up to and including the ">" that closes the body tag as part of the first "explode"
I hope that clarifies things a bit.
Justin
My body tag looks like this
<body leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
but it won't always have the same stuff in it.
this:
Code: Select all
$htm=explode("<body ",$file);
$html=explode("</body>",$htm[1]);leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
and then the rest of the document as expected.
I'm curious if I can include all the characters up to and including the ">" that closes the body tag as part of the first "explode"
I hope that clarifies things a bit.
Justin
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$innerhtml = preg_split("/<\/?body[^>]*?>/i",$file);I'm really out of my realm here so I appologize for all the basic questions. I'm trying to get a grasp on this, and it's starting to come together.
feyd, I'm using your code now and all is good but I can't seem to get the trailing ">" in the <body> tag to split. It's being included in the rest of the document.
I've been reading about "pattern syntax" in the docs and tried changing a few things around but I don't have the right combination.
am I correct in thinking that the "^" character
defined as: "negate the class, but only if the first character"
is the problem?
Again, thanks very much for any help on this.
Justin
feyd, I'm using your code now and all is good but I can't seem to get the trailing ">" in the <body> tag to split. It's being included in the rest of the document.
I've been reading about "pattern syntax" in the docs and tried changing a few things around but I don't have the right combination.
Code: Select all
$innerhtml = preg_split("/<\/?body[^>]*/i",$file);defined as: "negate the class, but only if the first character"
is the problem?
Again, thanks very much for any help on this.
Justin
Last edited by jds580s on Wed May 19, 2004 10:04 am, edited 1 time in total.
well if I can beat feyd, all you would need is to add the '?' syntax
grrrrrrrr, why did I even bother!?!?!?!

Code: Select all
bodyї^>]*?>