This seems to collect the actual code of the page, unless I messed up somewhere. Is it possible to collect the html source that would appear if you went to View -> Source ? Thanks
Use curl it might help you. visit php.net , you will get good help there about curl. I will soon send some example to capture source using curl.
<? $handle = fopen("http://www.example.com/", "r"); if ($handle) { while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose($handle); echo $buffer; //you will get all source in this buffer } ?> Code (markup): let me know if it works for you
file_get_contents, file, fread, and curl will all do the same thing, they will retrieve the content as parsed by the server that the file you're requesting resides on, and it is infact exactly the same source that Internet Explorer, Mozilla, Firefox, and any other browser or http1.0/1.1 || > client will retrieve. Hope that clears it up. If you're looking to get the source code of a php script, you'll have no luck at all, there's no way to achieve such things, php is a server side language; all php code is parsed before the content gets to a user / script / client / bot / crawler or whatever else .....
Maybe... just maybe a program called flashget will work. It's freeware. Too bad I can't try it out now (not at home)...
Oh I see. Would it be possible to turn a portion of php code into html the way it would be as viewed in a browser, and store the html code into a variable? Thanks.
The above stated methods do just that, however if you view that code in a browser it will appear the same as viewing the page itself. Maybe you could pass the html code to a text field where it would be viewed as code...
Well what I am looking to do is get my php code to turn into the html it would display when you view it in a browser, and put that html data into a variable. It doesn't necessarily have to be through getting the source from a page. Any way possible will do.
Hi, I am not sure whether this will help u.Try this link http://au2.php.net/fopen In that page, there is a class named HttpRequest.U can use that class to get the page source of an url.
no there isn't, classes aren't reference by .'s, just a friendly suggestion if you don't know the answer to a question then don't try to answer it you'll just create more confusion for the OP
you can get it if you are in the same server. It's like copying a file. As crackjoe said "file_get_contents, file, fread, and curl will all do the same thing". If there's such thing then no one will buy a script.
cURL is the quickest way to retrieve the information, more advanced but also more powerful than the other options.
<?php function getPage ($url) { if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); return curl_exec($ch); } else { return file_get_contents($url); } } ?> PHP: Neat little function. If you don't have cURL, it goes for file_get_contents. Otherwise, cURL away
curl_init (PHP 4 >= 4.0.2, PHP 5) curl_init -- Initialize a cURL session Description resource curl_init ( [string url] ) Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions. It was just the same.
You could try using output buffering. Assuming the PHP code you want to evaluate is in a variable named $phpCode: <?php ob_start(); eval($phpCode); $result = ob_get_contents(); ob_end_clean(); ?> Code (markup): See here for more details on output buffering: http://www.php.net/manual/en/ref.outcontrol.php