Home > Backend Development > PHP Tutorial > PHP simple crawler

PHP simple crawler

WBOY
Release: 2016-07-25 09:08:50
Original
1037 people have browsed it
  1. function get_urls($url)
  2. {
  3. $url_array=array();
  4. $the_first_content=file_get_contents($url);
  5. $the_second_content=file_get_contents($url);
  6. $pattern1 = "/http://[a-zA-Z0-9.?/-=&:+-_'"]+/";
  7. $pattern2="/http://[a-zA-Z0-9.]+/";
  8. preg_match_all($pattern2, $the_second_content, $matches2);
  9. preg_match_all($pattern1, $the_first_content, $matches1);
  10. $new_array1=array_unique($matches1[0]);
  11. $new_array2=array_unique($matches2[0]);
  12. $final_array=array_merge($new_array1,$new_array2);
  13. $final_array=array_unique($final_array);
  14. for($i=0;$i {
  15. echo $final_array[$i]."
    ";
  16. }
  17. }
  18. get_urls("http://www.baidu.com");
复制代码


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template