Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

[web] PHP: Opening a PHP file using a query string

Started by Tac-Tics Jun 5, 2006 at 9:05 AM 2 replies 850+ views
Original Post
Tac-Tics
Tac-Tics
I have 2 PHP scripts. One does a lot of data processing and the other acts as an HTML template which "drops in" a few GET values (echo $_REQUEST[...] type stuff). My problem is, I want to SAVE the HTML output from the template to a file from within the first PHP script. Currently, I have been trying file_get_contents, but after about 20 minutes of messing with it, I realized it doesn't work with HTML query strings. Simply put, I need a way to save the HTML output of template.php?key=value to a file with another PHP file.
Sander
Sander
Why not include the second file in the first one and capture the output with an output buffer (ob_start() - ob_get_contents())?
konForce
konForce
ob_start();
include('template.php');
$html = ob_get_clean(); // assigns the buffer to $html and clears it
BeanDog
BeanDog
Have you tried this?
$file = fopen('http://example.com', 'r');

PHP allows you to open a URL (including query strings, I assume) as a file stream. You could read the stream and save it to a file.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.