<?php
error_reporting("E_ALL^E_NOTICE");
//default_charset("utf-8");
mysql_connect("localhost","root","****");
mysql_select_db("test");
mysql_query("set names 'UTF8'");
$reg="#<h1>·<a href='(.*)' target='_blank'>(.*)</a><span>#iUs";
$con=file_get_contents("http://it.sohu.com/7/1002/17/column203661721.shtml");
iconv("GBK","UTF_8//IGNORE",$con);
preg_match_all($reg,$con,$matches);
//var_dump($matches);
foreach($matches[1] as $id=> $d )
{
$sql="INSERT INTO tmp(id,title,url )VALUES('NULL','".$matches[2][$id]."','".$d."')";
//echo $sql."<br/>";
//echo $matches[2][$id]."<br/>";
mysql_query($sql);
//echo $d;
error_reporting("E_ALL^E_NOTICE");
//default_charset("utf-8");
mysql_connect("localhost","root","****");
mysql_select_db("test");
mysql_query("set names 'UTF8'");
$reg="#<h1>·<a href='(.*)' target='_blank'>(.*)</a><span>#iUs";
$con=file_get_contents("http://it.sohu.com/7/1002/17/column203661721.shtml");
iconv("GBK","UTF_8//IGNORE",$con);
preg_match_all($reg,$con,$matches);
//var_dump($matches);
foreach($matches[1] as $id=> $d )
{
$sql="INSERT INTO tmp(id,title,url )VALUES('NULL','".$matches[2][$id]."','".$d."')";
//echo $sql."<br/>";
//echo $matches[2][$id]."<br/>";
mysql_query($sql);
//echo $d;
}
插入之后,中文显示乱码,已经转码了,为什么还这样、、、??
?>