seany123 Posted December 9, 2010 Share Posted December 9, 2010 it is possible to echo another websites source? ive tried, <?php $f = readfile("view-source:http://www.example.com/now"); ?> but i get an error: failed to open stream: Invalid argument is there any other way of being able to echo it? Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/ Share on other sites More sharing options...
Maq Posted December 9, 2010 Share Posted December 9, 2010 Check out: http://php.net/manual/en/function.file-get-contents.php Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1144991 Share on other sites More sharing options...
seany123 Posted December 9, 2010 Author Share Posted December 9, 2010 i dont see how it gets the source. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145031 Share on other sites More sharing options...
Rifts Posted December 9, 2010 Share Posted December 9, 2010 <?php $homepage = file_get_contents('http://www.example.com/'); echo $homepage; ?> Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145037 Share on other sites More sharing options...
litebearer Posted December 9, 2010 Share Posted December 9, 2010 Also might look into http://www.seopher.com/articles/scraping_website_content_with_php_using_curl Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145040 Share on other sites More sharing options...
Maq Posted December 9, 2010 Share Posted December 9, 2010 i dont see how it gets the source. Did you read the manual? It explains how it works and gives you multiple examples of how to use it. There are other options depending on exactly what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145045 Share on other sites More sharing options...
seany123 Posted December 9, 2010 Author Share Posted December 9, 2010 <?php $homepage = file_get_contents('http://www.example.com/'); echo $homepage; ?> that doesnt work... i actually want the source code displayed not the html. what im expecting is lines of html code. <?php $homepage = file_get_contents('http://www.google.com/'); echo $homepage; ?> shows the search bar and buttons, but what i wanna see is the source, the inputs etc Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145066 Share on other sites More sharing options...
Maq Posted December 9, 2010 Share Posted December 9, 2010 that doesnt work... i actually want the source code displayed not the html. what im expecting is lines of html code. You just contradicted yourself. What exactly are you trying to see? You cannot see server side code, only client side. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145068 Share on other sites More sharing options...
Andy-H Posted December 9, 2010 Share Posted December 9, 2010 $addr = 'http://google.com'; $fp = file_get_contents($addr); echo stripslashes(htmlentities($fp, ENT_QUOTES)); Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145069 Share on other sites More sharing options...
seany123 Posted December 9, 2010 Author Share Posted December 9, 2010 HTML source code. when you right click and view page source... thats what i want to see. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145083 Share on other sites More sharing options...
Maq Posted December 9, 2010 Share Posted December 9, 2010 HTML source code. when you right click and view page source... thats what i want to see. The code provided will do that. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145087 Share on other sites More sharing options...
seany123 Posted December 9, 2010 Author Share Posted December 9, 2010 $addr = 'http://google.com'; $fp = file_get_contents($addr); echo stripslashes(htmlentities($fp, ENT_QUOTES)); thats working brilliantly, now i need help with one more thing. i want to search for 2 things inside the source code. first thing is a image... i was thinking of somehow making a search for starting in http:// and ending in .jpg second i need to find the same thing for a .avi file starting in http:// and ending in .avi they need to then be set as variables to i can use them with my db. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145088 Share on other sites More sharing options...
BlueSkyIS Posted December 9, 2010 Share Posted December 9, 2010 the only reason "that works brilliantly" is that you can now see the HTML-formatted HTML in your browser. however, what you are seeing is no longer the same as the source code you see on the website. Maq is correct: the previous code is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145099 Share on other sites More sharing options...
seany123 Posted December 10, 2010 Author Share Posted December 10, 2010 the only reason "that works brilliantly" is that you can now see the HTML-formatted HTML in your browser. however, what you are seeing is no longer the same as the source code you see on the website. Maq is correct: the previous code is what you want. for some reason the other code didn't show the source, the current code may not show the true source but it does show the part of the code I need. now i just gotta search for the two links in the code. what would be the most efficient way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145375 Share on other sites More sharing options...
laffin Posted December 10, 2010 Share Posted December 10, 2010 I much prefer $addr = 'http://google.com'; $fp = file_get_contents($addr); header('Content-type: text/plain'); echo $fp; Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145392 Share on other sites More sharing options...
QuickOldCar Posted December 10, 2010 Share Posted December 10, 2010 It sounds to me you need something more like html dom and to fetch tags from the page, like images,href, or anything else you want located in a divider or in the html. http://simplehtmldom.sourceforge.net/ Quote Link to comment https://forums.phpfreaks.com/topic/221132-echo-external-websites-html-source-code/#findComment-1145429 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.