How would you store the html output of a remote php file in a variable?

I want to write a php script that sends an html email – the content of which is supplied by the output of another php file.

Do you know of any way to do this?

Many thanks

2 Responses to “How would you store the html output of a remote php file in a variable?”

  • mia:

    Either using a database to store the values, or you could write to a text file and then read the text file into variables in your php script, or you may be able to use session variables depending on what you mean by "remote php file".

    The other option would be to parse the values into a stream writer (I’m normally c#.net, but I think the php equivalent is the Stream Handler) and send the stream to your php script to read. That would avoid the file write/read, but the data can still be accessed by code like you would if it were text.
    Check out: http://www.php.net/manual/en/intro.stream.php

  • null 0:

    If the php file is on a completely different website, then you can just use:

    $output = file_get_contents("http://site.com/whatever.php");

    That’s only if it’s on another site though, if its just another php file then you can use "output buffering" as such:

    ob_start();
    include("mailcontent.php");
    $output = ob_get_contents();
    ob_end_clean();

    That will run any code in mailcontent.php and store any output into a buffer, and then all of that content will be in the $output variable that you can use for the body of your email.

Leave a Reply