Web Analytics Made Easy -
StatCounter $page = output of php-parser ??? - CodingForum

Announcement

Collapse
No announcement yet.

$page = output of php-parser ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • $page = output of php-parser ???

    Hi,

    this might seem as an odd question about PHP, but I'm simply asking it because I'm interested in the possibilities of PHP. Okay, here it comes: Is it possible to capture a complete parsed page in a variable. In other words: I want the output of the php parser to be the value of my variable $page.

    Example:

    snipppet of 'mypage.php?name=Michiel'

    <HTML>
    <HEAD>
    <TITLE>
    <?PHP
    if (IsSet($name)) print ("Homepage of $name");
    else print ("Homepage of anonymous");
    ?>
    </TITLE>

    etc. etc.

    Now I would like, somehow that the value of my variable $page is gona be:

    $page = "<HTML><HEAD><TITLE>Homepage of Michiel</TITLE> etc. etc."

    I hope my question is clear enough

    Thanx Michiel

  • #2
    not exactly with you but I thnk you mean either this
    PHP Code:
    $yaks=implode('',file('mypage.php?name=Michiel')); 
    or this ?

    PHP Code:
    if (IsSet($name)) {
    $title="Homepage of $name"); 
    }else{
    $title"Homepage of anonymous"
    }

    $str="
    <HTML> 
    <HEAD> 
    <TITLE> 
    $title
    </TITLE> 
    </HEAD><BODY> etc etc
    "
    ;

    echo 
    $str

    either way the answer is yes
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

    Comment


    • #3
      Hmm,

      no this is not exactly what I mean, thanks though for your reply . I'll try to explain again what is is that I'm looking for:

      When you call a php-script in your browser, the php-script is parsed on the server by a php-parser, right? The output of the parser is pure html-code which is displayed by the browser. What I want to do is parse my php-script entirely and then put the output in a variable $page instead of displaying the output in the browser. So then the content of $page would be everything from '<HTML><HEAD> ...... 'til </BODY></HTML>'.

      I hope this makes my question a bit more understandable ....

      Regards, Michiel

      Comment


      • #4
        Here is a link that might help

        I am wroking on a page as well, and I was looking at this page today. I think that it will help you. It is located at:

        http://www.phpbuilder.com/columns/argerich20010125.php3

        This page actually talks about compression, but it might help.
        I would think that you could just do this:

        $yaks=implode('',file('mypage.php?name=Michiel'));
        What firepages said, but this might give you a little more to look at. I don't know, but I hope that it helps.

        ~evlich

        Comment


        • #5
          Michiel, have you tried to open an URL with the file() example above? I mean, like

          $yaks=implode('',file('http://www.example.org/mypage.php?name=Michiel'));

          That should retrieve the contents of mypage.php, parsed by the PHP engine and assign the value to the $yaks variable.
          fopen wrappers must be enabled for URLs though, see the tip at

          http://www.php.net/manual/en/function.file.php
          De gustibus non est disputandum.

          Comment


          • #6
            rather than
            PHP Code:
            $yaks=implode(" ",file('http://www.example.org/mypage.php?name=Michiel')); 
            I personnaly think it would be better to use
            PHP Code:
            $yaks=implode("\n",file('http://www.example.org/mypage.php?name=Michiel')); 
            Not much change but if ever you come to print $yaks then the page won't appear on a whole line in the page source.
            I don't suffer from insanity, I enjoy every single minute of it!

            Comment


            • #7
              @Flamerule: I thought that was unneccessary, because the manual says:

              Identical to readfile(), except that file() returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached
              taken from http://za2.php.net/manual/en/function.file.php

              De gustibus non est disputandum.

              Comment


              • #8
                woups

                *hides*
                I don't suffer from insanity, I enjoy every single minute of it!

                Comment

                Working...
                X