arturo322 Posted September 29, 2010 Share Posted September 29, 2010 I've been making our thesis and i've been thinking if there is a function or method perhaps to get the interpreted codes(the codes you see if you get the source of the site on browsers) into another text file. something like fwrite the intertpreted code to a text file Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/ Share on other sites More sharing options...
jcbones Posted September 29, 2010 Share Posted September 29, 2010 Sure, this should work. $filename = 'myfile.php'; //file whos output you want to capture. $storageFile = 'myfile.html'; //file where you want to store the data. $file = file_get_contents($filename); file_put_contents($storageFile,$file); Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116951 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 Thank you but, It just like replicated the main php file. i want the interpreted code to be stored, the html codes you see in viewing your source in browser brower>>view>>sourcecode this source code is the html code i want to store, is this possible? thank you Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116952 Share on other sites More sharing options...
jcbones Posted September 29, 2010 Share Posted September 29, 2010 Pass the filename as a address. IE: $filename = 'http://localhost/test.php'; Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116955 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 I tested it on my login.php. By The Way I tested the first one here too my server took a while to respond and gave me this error Warning: file_get_contents(http://localhost/thesis/login.php) [function.file-get-contents]: failed to open stream: HTTP request failed! in C:\xampp\htdocs\thesis\login.php on line 16 Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\thesis\login.php on line 16 Line 13 $filename = 'http://localhost/thesis/login.php'; //file whos output you want to capture. Line 14 $storageFile = 'test.html'; //file where you want to store the data. Line 15 // Blank line Line 16 $file = file_get_contents($filename); Line 17 file_put_contents($storageFile,$file); Is there something wrong in naming the URL? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116959 Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 It looks like you do, but make sure you have 'allow_url_fopen' enabled in your php.ini. Don't forget to restart the server if you make any changes. Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116961 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 @thorpe its on when i checked it. ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. allow_url_fopen = On thanks Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116962 Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 @thorpe its on when i checked it. Yeah, I thought it might be. Seems for whatever reason though, its timing out. Shouldn't really take too long to execute. You can access the page easily enough through a browser? Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116965 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 before i changed the $filename = login.php (No errors fast server response) to $filename = 'http://localhost/thesis/login.php'; (Errors with a little long time to respond) Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116968 Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 Your code needs to be accessed via a url in order for the server to execute it. The other thing you could do would be to use output buffering to trap all output in a buffer, then write that output to a file. This will likely require modification of your code however unless you setup auto_prepend_file to enable the buffer and auto_append_file to write the file. Take a look at ob_start. Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116969 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 oh yea i just remebered i placed output_buffering = on on my php.ini do you think this is a factor in this matter? I'm a little new to php scripting and not used to most of its functions, I've read Php manual the .chm file but it says that ob_start -- Turn on output buffering Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116971 Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 oh yea i just remebered i placed output_buffering = on on my php.ini do you think this is a factor in this matter? I'm a little new to php scripting and not used to most of its functions, I've read Php manual the .chm file but it says that ob_start -- Turn on output buffering Output buffering doesn't really help you unless you plan on using what's in the buffer. It has nothing to do with the issue you posted above, I was suggesting it as another possible solution to your overall problem though. Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1116974 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 I can't seem understand how to use the function can i have sample codes that has Ob_start function with it? so that i can analyze and understand it better Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1117123 Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 ob_start(); // your code would go here. echo "outputted from code"; $str = ob_get_contents(); $str would now hold the output of all code between ob_start() & ob_get_contents(). Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1117124 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 i tried to do it like this, i placed <?php ob_start() ?> at the first line of the file then placed this on the last part $str = ob_get_contents(); $storageFile = 'test.html'; //file where you want to store the data. file_put_contents($storageFile,$str); but it seems that it doest make the test.html file Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1117136 Share on other sites More sharing options...
arturo322 Posted September 29, 2010 Author Share Posted September 29, 2010 My bad stupidity impulse case solved i didnt browse the folder properly the code isent were correct thanks to you thorpe and jcbones thhis forums helps a lot Quote Link to comment https://forums.phpfreaks.com/topic/214673-is-there-a-function-that-prints-the-interpreted-php-code/#findComment-1117138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.