HTML Download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kramer
Forum Newbie
Posts: 1
Joined: Wed Jan 14, 2004 5:17 am

HTML Download

Post by Kramer »

Hi. I'm relatively new to PHP and am wondering if you can help me here.

I'm trying to write a script that will download an HTML page and then search through it for a specific phrase and do a few more things, but that's not important at this stage.

Problem is I'm having a bit of trouble 'allocating' the page to a variable. This is the code I have so far:
$html = implode ('', file ('http://www.domain-name.com'));
echo $html;

The problem is that $html seems to be empty or a string of length 0. I think this is because the site I want to get (not http://www.domain-name.com) requires authentication (which I do have), but I'm not sure. The specific page is also a Perl page (*.pl)

Is that likely to be why $html turns out to be empty or am I doing something wrong with the code.

Is there anyway to send the authentication using PHP? The login box is a msgbox type window thing (hope you know what I mean)

Thanks in advance,
Kramer
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

implode() is used to crunch an array into a string, I'm not sure why you're using it here.

If you want to load an entire website page into a variable so you can "search" through it (sounds dodgy to me) then something like the following might help... and yes, if the site requires a username and password to access then don't expect to be able to load the page.

Code: Select all

<?php

ob_start();
readfile "http://www.somewhere.com/thePage.html";
$contents = ob_get_contents();
ob_end_clean();

// You should now have the HTML contents stored in the
// $contents variable which you can do what you want with.

echo $content;

?>
Like I said though if the page you are trying to load requires a username and password then you won't be able to load it.. unless you have the username and password obviously.
User avatar
code_monkey
Forum Newbie
Posts: 16
Joined: Tue Jul 08, 2003 6:13 am
Location: UK
Contact:

HTML download

Post by code_monkey »

have a look at http://sourceforge.net/projects/snoopy/
it might be able to help with what you want
Post Reply