erasam Posted August 2, 2007 Share Posted August 2, 2007 can anyone tell me how to use PHP to copy the whole content of a webpage? THX Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/ Share on other sites More sharing options...
phpSensei Posted August 2, 2007 Share Posted August 2, 2007 You can use a function method... <?php fucntion YourFunctionName(){?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> </body> </html> <?php } ?> Put those two php codes at both start and end of your document... then included it as a function, hope this is what you ment. Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313535 Share on other sites More sharing options...
hitman6003 Posted August 2, 2007 Share Posted August 2, 2007 What do you mean "whole content of a webpage"? You can get the html of a page using the file functions...for example: $html = file_get_contents("http://www.phpfreaks.com"); Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313538 Share on other sites More sharing options...
teng84 Posted August 2, 2007 Share Posted August 2, 2007 use file_get_contents http://ca.php.net/manual/en/function.file-get-contents.php note you can only get the html file not the server script Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313539 Share on other sites More sharing options...
erasam Posted August 2, 2007 Author Share Posted August 2, 2007 OK now I can get the content of a webpage, but how can I copy the text in that webpage using PHP? Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313555 Share on other sites More sharing options...
teng84 Posted August 2, 2007 Share Posted August 2, 2007 first tell us how do you want to use the page like the data u get out of the get contents Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313558 Share on other sites More sharing options...
erasam Posted August 2, 2007 Author Share Posted August 2, 2007 first tell us how do you want to use the page like the data u get out of the get contents Actually, my boss told me to copy a news (in text format) from a website , then paste it to an email and sent to him. I am wondering if there are any PHP scripts can automate this process. THX Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313561 Share on other sites More sharing options...
teng84 Posted August 2, 2007 Share Posted August 2, 2007 file get contents works this way it reads and get the page as if its a text now to get the specific data you have to explode it and get the array that you really need sample explode the page by <p> represent the paragraph can you give me sample site to get Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313572 Share on other sites More sharing options...
erasam Posted August 2, 2007 Author Share Posted August 2, 2007 http://appledaily.atnext.com/template/apple_sub/art_main.cfm?&iss_id=20070731&sec_id=38167&subsec_id=38173&art_id=7384932&cat_id=7003950&coln_id=7003951 Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313587 Share on other sites More sharing options...
teng84 Posted August 2, 2007 Share Posted August 2, 2007 i actually dont understand is it chinese??? ok do it your self $x=file_get_contents('the site here'); $array=explode('<',$x);//you can put the specific html tag that you think can get the exactdata u need print_r($array); //or print_r(file('location here')); //now you have everything in array but if you sue this it will cause error when the site you where //you get the data change the format //or you use curl Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313589 Share on other sites More sharing options...
erasam Posted August 2, 2007 Author Share Posted August 2, 2007 It works, THX Quote Link to comment https://forums.phpfreaks.com/topic/62966-solved-how-to-copy-the-content-of-a-webpage-using-php/#findComment-313639 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.