kevloink Posted June 11, 2007 Share Posted June 11, 2007 Ok. From www.whatever.com/index.php how can I get the source for www.anothersite.com/page.php ? Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/ Share on other sites More sharing options...
btherl Posted June 11, 2007 Share Posted June 11, 2007 You can send an email to the webmaster and ask for it. Do you own www.anothersite.com? Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272111 Share on other sites More sharing options...
btherl Posted June 11, 2007 Share Posted June 11, 2007 hmm.. do you want the php source or the html source? Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272112 Share on other sites More sharing options...
kevloink Posted June 11, 2007 Author Share Posted June 11, 2007 Those sites were examples, lol. I just want the HTML source. Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272122 Share on other sites More sharing options...
soycharliente Posted June 11, 2007 Share Posted June 11, 2007 You go to the page, hold control, and push 'u'? Or how can one page access the HTML code of another page? Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272127 Share on other sites More sharing options...
sKunKbad Posted June 11, 2007 Share Posted June 11, 2007 $lines = file('http://www.anothersite.com/page.php/'); foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272148 Share on other sites More sharing options...
sKunKbad Posted June 11, 2007 Share Posted June 11, 2007 i tried to edit my post, but the time to edit had expired. I got that code from the php docs on php.net. I was hoping to figure out a way to leaving in the whitespace, so that the html looks nicer when displayed, but I haven't figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272154 Share on other sites More sharing options...
soycharliente Posted June 11, 2007 Share Posted June 11, 2007 trim() http://www.php.net/trim Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272258 Share on other sites More sharing options...
sKunKbad Posted June 11, 2007 Share Posted June 11, 2007 i don't want to trim the whitespace, i want it left in! Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272370 Share on other sites More sharing options...
trq Posted June 11, 2007 Share Posted June 11, 2007 I think your looking for nl2br(). Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272371 Share on other sites More sharing options...
sKunKbad Posted June 11, 2007 Share Posted June 11, 2007 Actually, when you look at the actual HTML code that is opened, there are tab characters on many lines, but they are not being represented in the output. Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272454 Share on other sites More sharing options...
smc Posted June 11, 2007 Share Posted June 11, 2007 Also keep in mind the PHP files your accessing are post-parsed. Any PHP in the file will return just as plain HTML since PHP is operated server side. And yeah I also think your looking for nl2br() but just incase that doesn't work keep in mind you can always cheat and do something like $file = str_replace( " ", "<WHITE>", $file ); process your file $file = str_replace ( "<WHITE>", " ", $file ); This basically transforms the white space to data PHP won't touch, then transforms it back again. Haven't tested it, but I don't see why it wouldn't work. Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272457 Share on other sites More sharing options...
sKunKbad Posted June 11, 2007 Share Posted June 11, 2007 This worked: <?php $lines = file('http://www.yoursite.com'); foreach ($lines as $line_num => $line) { echo str_replace(" "," ",htmlentities($line)) . "<br />\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272508 Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 file_get_contents() would work too. Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272511 Share on other sites More sharing options...
sKunKbad Posted June 12, 2007 Share Posted June 12, 2007 I couldn't figure out how to do it with file_get_contents() and still have the appropriate whitespace and line breaks. I did however provide a good solution to the original question, so maybe somebody else can come up with another way or a better way and share. I'm still a php newbie! Quote Link to comment https://forums.phpfreaks.com/topic/55037-view-the-source-of-another-page/#findComment-272788 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.