Hi all, I am a newbie in php. I want to know the code to download the source code of a webpage when its url is specified in the php program.
So this tag works for a file to get as input. It takes a file. but am not sure whether this function is useful in downloading the source code when i give a url like "http://www.google.com". So will this work under this condition?
Okay let me try and understand you better. You want to put in a url and then be prompted to download the source code?
Yes dude. If i mention any url link, the program should download the source code of the corresponding web page. I have the coding in java. But not in php. For example, i will give the java coding here: import java.io.*; import java.util.*; import java.net.*; public class Downloadsourcecode { public static void main(String arg[]) throws Exception { int c; URL hp=new URL("http://www.yahoo.com"); URLConnection hpc=hp.openConnection(); InputStream input=hpc.getInputStream(); System.out.println("Content"); while((c=input.read())!=-1) System.out.print((char)c); input.close(); } } Just try running this code. You will get the output as a source code of the specified web site address.
$ch = curl_init(); $options = array(CURLOPT_FOLLOWLOCATION=>0, CURLOPT_USERAGENT=>$_SERVER['HTTP_USER_AGENT']); curl_setopt ($ch, CURLOPT_URL, $login_url); curl_setopt_array ($ch, $options); $page = curl_exec ($ch); Code (markup): $page will contain the source code. Thanks.
Lolz, curl sees that output only that a browser see. So now confusion should be there whether is it PHP source code or HTML source code. OFCOURSE IT'S A HTML SOURCE CODE
So what if the page has got lots of other scripts like javascript or php tags? I do not want only the html tags but all the coding tags from the source.
It depends on what you call contents. Some will just get you the html. You will need to do a little more work if you want all the images, scripts, etc.
Well, if you curl a page, you will get all things, everything that is embedded inside the the page. No exceptions.
Thank you for your explanation guys. I would want you to have a look at this link. http://forums.digitalpoint.com/showthread.php?p=10400368#post10400368
PHP is a server side script, so there is no way for a visitor to see the php code. Absolutely NO WAY. You can just see what the php code outputs to the browser. fopen and cURL are the best way to do that. I am sure the point of this is to copy content from sites not source code.
Exactly dude. And you know guys, i have successfully finished the first module of my project with your help. Now that i have finished in java fully. Since i had only one day time, i went for java. But surely will try to do the same with php very soon once when i finish my entire project.