$array[0] = "<html><head><title>Test</title></head><body>";
$array[1] = "<p>This is where my page goes</p>";
$array[2] = "</body></html>";

    Sorry, should have explained better. I need to be able to split any html page at those locations. Even if they have something like this <body onLoad="somefunction();"> instead of just <body>. What I'm going to be doing is opening a page with my PHP script and I need to put those sections in different places. Any ideas?

      I took a look at that, but I don't really know how to use it...Could you maybe provide me with an example?

        If I understood you correctly, this might be a solution:

        <?
        $html = '
        <html>
        <head>
        <title></title>
        <meta name="author" content="swon">
        </head>
        <body>
        <!--endHead//-->
        </body>
        <!--endBody//-->
        </html>';

        $contentfooter = explode("<!--endBody//-->",$html);
        echo "<textarea>$contentfooter[1]</textarea>";

        $contentbody = explode("<!--endHead//-->",$contentfooter[0]);
        echo "<textarea>$contentbody[1]</textarea>";

        $contenthead = explode("<!--endHead//-->",$contentbody[0]);
        echo "<textarea>$contenthead[0]</textarea>";

        ?>

        width the comments between, the body can have anything, it doesn't matter!

          I don't think that is what I need. I need to open any html page, without any special comments added and split it where I specified above. Basically what it is for is to load the three sections into three textareas, so the body can be edited, and the I can rejoin to save. hmm...

            Ok,
            First off, get the length of the document. Then, get the position of the end of the <body> statement. Load the text value from position 0-$startofbody into a variable.

            Then load $startofbody+1 to $beginningofendofbody into second variable or array.

            Then from $beginningofendofbody+1 to the end of the document.

            I've done this in Java, and it works well, though I'm not sure of the exact php functions. But I know you can get the location of strings from a line of text and things of that nature with php.

            Does this make sense?

              The functions you're looking for are strpos() and strrpos(). This will give you the position of a substring in php.

              You will also need strlen(). This will give you the length of the original html document.

                couldn't you split the 3 sections into files called header.php, content.php, and footer.php, then include the files in index.php?

                I do that since I can open php files in notepad and since I can save plain html as a php file with no complications.

                Hope that helps

                  NoFear. Yes, your suggestion make sence to me, but how do I get the position of the <body> tag. If it were alway <body> it'd be fine, but what if it's <body onLoad="someFunc();">?? The </body> would be no problem, because that would always be </body>

                  Gary, I need to be able to dynamically open any file, I be able to use a header and footer, becuse I won't always be making the pages. If I were, I'd just add a comment in like <!--Begin Body--> and <!--End Body--> and split it there. But, I need to be able to dynamically do this to aany file. Make sence?

                    Assuming you have your HTML page into a string, and you define a 'start' and 'stop' string to extract the parts, something like this should work and in fact is probably much easier than regex.

                    $string = "<html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>";
                    $start = "<BoDy";
                    $stop = "</bOdY>";
                    
                    $pos_1 = strlen($string)-strlen(stristr($string,"$start"));
                    $pos_2 = ((strlen($string)-strlen(stristr($string,"$stop")))+strlen("$stop")) - $pos_1;
                    
                    echo $result = substr($string, $pos_1, $pos_2);
                    

                    The way around the body issue is to forget about using the greater than bracket at the end. Hope this makes sense.

                      Thanks so much for your help, theeper. That wasn't quite what I was looking for, but I think someone found a way to do it for me. What your script does is takes <body...> page here </body> What I actually needed what three variables,

                      one with
                      <html>
                      <head>
                      </head>
                      <body...>

                      one with
                      <p>page here</p>

                      and one with
                      </body>
                      </html>

                      Anyway, thanks for your help -- it was much appreciated. 😃

                        This will your solution for spliting file into 3 section :

                        <?
                        $string = "<html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>";
                        
                        $result = htmlentities($string);
                        $result = ereg_replace ("\n", "", $result);
                        $result = ereg_replace (" ", "&nbsp;", $result);
                        print "Source File : <br>";
                        print "==========================================<br>";
                        print ( $result );
                        print "<br>==========================================<br>";
                        print "<br><br>";
                        
                        
                        $start1 = "<html";
                        $stop1 = "<body";
                        
                        $start2 = "<BoDy";
                        $stop2 = "</bOdY>";
                        
                        $srtncount  = strlen($string);
                        $pos_1 = $srtncount - strlen(stristr($string,"$start1"));
                        $pos_2 = (($srtncount - strlen(stristr($string,"$stop1")))+strlen("$stop1")) - $pos_1;
                        $result = substr($string, $pos_1, $pos_2-5);
                        //body tag
                        $new = substr($string,$pos_2-5,$srtncount);
                        $newsrtncount = strlen($new);
                        $pos_1 = $newsrtncount - strlen(stristr($new,"<body"));
                        $pos_2 = (($newsrtncount - strlen(stristr($new,">")))+strlen(">")) - $pos_1;
                        $newresult = substr($new, $pos_1, $pos_2);
                        $result = $result.$newresult;
                        $result = htmlentities($result);
                        $result = ereg_replace ("\n", "", $result);
                        $result = ereg_replace (" ", "&nbsp;", $result);
                        print " Section First : <br>";
                        print "=============================================<br>";
                        print ( $result );
                        print "<br>=========================================<br>";
                        print "<br>";
                        
                        $bodylen = strlen($newresult); //length of body tag
                        $pos_3 = strlen($string)-strlen(stristr($string,"$start2"))+$bodylen;
                        $pos_4 = ((strlen($string)-strlen(stristr($string,"$stop2")))+strlen("$stop2")) - $pos_3-strlen("</body>");
                        
                        $result = substr($string, $pos_3, $pos_4);
                        $result = htmlentities($result);
                        $result = ereg_replace ("\n", "", $result);
                        $result = ereg_replace (" ", "&nbsp;", $result);
                        print " Section second : <br>";
                        print "=============================================<br>";
                        print ( $result );
                        print "<br>=========================================<br>";
                        print "<br>";
                        
                        $result = substr($string, $pos_3+$pos_4,$srtncount);
                        $result = htmlentities($result);
                        $result = ereg_replace ("\n", "", $result);
                        $result = ereg_replace (" ", "&nbsp;", $result);
                        print " Section Third : <br>";
                        print "==============================================<br>";
                        print ( $result );
                        print "<br>==========================================<br>";
                        print "<br>";
                        
                        ?>
                        
                        

                        OUT PUT is :

                        Source File :

                        <html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>

                        Section First :

                        <html><head><title>Test</title></head><body onload='something'>

                        Section second :

                        <p>This is where my page goes</p>

                        Section Third :

                        </body></html>

                          Here's what I finally ended up using.

                          $content="<html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>";
                          $content3 = $content;
                          $content = strtolower($content);
                          $pos=strpos($content,"<body");
                          $content1=substr($content3,$pos,strlen($content));
                          $content2=substr($content3,0,$pos);
                          $pos1=strpos($content1,">");
                          $done[0] = substr($content3,0,strlen($content2)+$pos1+1);
                          $pos2=strpos($content1,"</body");
                          $done[1] = substr($content3,strlen($content2)+$pos1+1,$pos2-6);
                          $done[2] = substr($content1,$pos2,strlen($content1));
                          echo $done[0];
                          echo "InBetween";
                          echo $done[1];
                          echo "InBetween";
                          echo $done[2];
                            Write a Reply...