Page 1 of 1
get info from remote web page
Posted: Thu Dec 07, 2006 5:05 pm
by kingconnections
Ok - so say that I want to have my script open a url and get text from a remote web page. Is this possible? If so how would I go about doing something like this?
ie
http://support.microsoft.com/kb/232039/en-us
and I wanted my script to return
Windows 2000 Upgrade Paths
Thanks in advance
Posted: Thu Dec 07, 2006 5:41 pm
by ok
So you want to get page title...
I like using regular functions for doing this (and not regex):
Code: Select all
$url = "http://support.microsoft.com/kb/232039/en-us";
$content = file_get_contents($url);
$find_open_tag = "<title>";
$position_start = strpos($content, $find_open_tag);
if($position_start === false)
{
echo "Page doesn't have a title!";
}
else
{
// Move the pointer to the end of the opening title tag...
$position_start = $position_start + strlen($find_open_tag);
// Find the closing title tag: </title>
$find_close_tag = "</title>";
$position_end = strpos($content, $find_close_tag);
if($position_end === false)
{
echo "Page doesn't have a closing title tag!";
}
else
{
// Read the title...
$title = substr($content, $position_start, $position_end-$position_start);
}
}
echo $title;
Posted: Thu Dec 07, 2006 5:50 pm
by John Cartwright
Code: Select all
$content = file_get_contents('http://support.microsoft.com/kb/232039/en-us');
preg_match('#<title>(.*?)</title>#s', $content, $matches);
echo '<pre>';
print_r($matches);
I'd prefer regular expression in this case, or likely
http://www.php.net/manual/en/function.p ... .php#46790
Posted: Thu Dec 07, 2006 11:02 pm
by kingconnections
Dude, you guys rock!!!! Thanks for the info.