Creating a Search Application -
(Page 15 of 29 )
In this function we will take care of obtaining the source from a URL. We will open a connection to the URL with the fopen() function and then read up to 25,000 bytes of the source with the fread() function. Once we have obtained the source from the URL, we will run it through the strip_tags() function to remove any HTML tags. We will also replace any entities with a literal space character. This is so we can split the words on spaces later on.
If we are unable to open a connection to the URL, the function will return FALSE, otherwise it will return the source.
<?php function _getData($url) { $filehandle = @fopen($url, 'r'); if(!$filehandle) { echo "Could not open URL ($url).<br />\n"; $return = FALSE; } else { $data = fread($filehandle, 25000); fclose($filehandle); $data = strip_tags ($data); $data = str_replace('&nbsp;', ' ', $data); $return = $data; } return $return; } ?> |
Next: >>
More Database Articles Articles
More By Matt Wade