Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 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
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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)

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @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


  • #8
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    woups

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •