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
get info from remote web page
Moderator: General Moderators
-
kingconnections
- Forum Contributor
- Posts: 137
- Joined: Thu Jul 14, 2005 4:28 pm
So you want to get page title...
I like using regular functions for doing this (and not regex):
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;- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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);-
kingconnections
- Forum Contributor
- Posts: 137
- Joined: Thu Jul 14, 2005 4:28 pm