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


No announcement yet.

$page = output of php-parser ???

  • Filter
  • Time
  • Show
Clear All
new posts

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


    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.


    snipppet of 'mypage.php?name=Michiel'

    if (IsSet($name)) print ("Homepage of $name");
    else print ("Homepage of anonymous");

    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:
    or this ?

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

    </HEAD><BODY> etc etc


    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)


    • #3

      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


      • #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:

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

        What firepages said, but this might give you a little more to look at. I don't know, but I hope that it helps.



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


          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

          De gustibus non est disputandum.


          • #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:
            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!


            • #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.


              • #8

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