Home >php教程 >PHP源码 >淘宝分类ID

淘宝分类ID

PHP中文网
PHP中文网Original
2016-05-25 17:00:301507browse

php代码

$url = "http://list.taobao.com/browse/cat-0.htm";
  $html = file_get_contents($url);
  echo &#39;<meta charset="UTF-8">&#39;;
  $pattern=&#39;/\<a\s+href\=\"http\:\/\/list\.taobao\.com\/itemlist\/.*?\&cat\=([0-9]+)\"\s+target\=\"\_blank\"\>(.*?)\<\/a\>/&#39;;
  preg_match_all($pattern, $html, $array, PREG_SET_ORDER);
  foreach($array as $item) {
   echo $item[1] . "=>" . mb_convert_encoding($item[2], &#39;UTF-8&#39;, &#39;GB2312&#39;);
   echo "<br />";
  }
Statement:
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