ホームページ  >  記事  >  バックエンド開発  >  数据库 - PHP向mysql中写数据,在phpmyadmin中为空,直接打印有数据?

数据库 - PHP向mysql中写数据,在phpmyadmin中为空,直接打印有数据?

WBOY
WBOYオリジナル
2016-06-06 20:28:031083ブラウズ

<code>function makePage($link)
{
......
//当网址属于xuegong.hubu
else if(strstr($link, 'xuegong.hubu'))
{
$page = curl_init();
curl_setopt($page, CURLOPT_URL , $link);
curl_setopt($page, CURLOPT_RETURNTRANSFER , 1);
$content = curl_exec($page);
$content = stristr($content, 'class="title"');
$content = stristr($content, 'class="bottom"', true);
$content = str_replace('class="title">', '', $content);
$content = strip_tags($content,'');
$content = stristr($content, '责任编辑',true);
$content = trim($content);
$content = str_replace("\r\n", "
", $content);
$content = preg_replace('/(<br>){2,}/', '
', $content);
$content = str_replace('href="', 'href="http://xuegong.hubu.edu.cn', $content);
return $content;
}
}
//只写出关键代码
$content = mysql_real_escape_string(makePage($notice[1][$key]));
$sql = 'insert ignore into php_notice(title,link,date,content) values("'.$value.'","'.$notice[1][$key].'","'.$notice[2][$key].'","'.$content.'");';
mysql_query($sql) or die(mysql_error());</code>

我是把项目放在sae上面,数据库都连接了,抓取其他网页的内容写入数据库都没问题,但是碰到xuegong的网页写入数据库在PHPMyAdmin查看为空。
数据库 - PHP向mysql中写数据,在phpmyadmin中为空,直接打印有数据?

PHP也没有提示错误,而且将内容打印出来也是对的,就是写入数据库之后变成了空格,编码都是utf-8。不知何解,求教

回复内容:

<code>function makePage($link)
{
......
//当网址属于xuegong.hubu
else if(strstr($link, 'xuegong.hubu'))
{
$page = curl_init();
curl_setopt($page, CURLOPT_URL , $link);
curl_setopt($page, CURLOPT_RETURNTRANSFER , 1);
$content = curl_exec($page);
$content = stristr($content, 'class="title"');
$content = stristr($content, 'class="bottom"', true);
$content = str_replace('class="title">', '', $content);
$content = strip_tags($content,'');
$content = stristr($content, '责任编辑',true);
$content = trim($content);
$content = str_replace("\r\n", "
", $content);
$content = preg_replace('/(<br>){2,}/', '
', $content);
$content = str_replace('href="', 'href="http://xuegong.hubu.edu.cn', $content);
return $content;
}
}
//只写出关键代码
$content = mysql_real_escape_string(makePage($notice[1][$key]));
$sql = 'insert ignore into php_notice(title,link,date,content) values("'.$value.'","'.$notice[1][$key].'","'.$notice[2][$key].'","'.$content.'");';
mysql_query($sql) or die(mysql_error());</code>

我是把项目放在sae上面,数据库都连接了,抓取其他网页的内容写入数据库都没问题,但是碰到xuegong的网页写入数据库在PHPMyAdmin查看为空。
数据库 - PHP向mysql中写数据,在phpmyadmin中为空,直接打印有数据?

PHP也没有提示错误,而且将内容打印出来也是对的,就是写入数据库之后变成了空格,编码都是utf-8。不知何解,求教

输出SQL语句直接在phpmyadmin运行看看?
你这么说别人也看不出是什么问题。
另外检查下你的字段类型是什么
话说你在百度知道问了又到这来这样好吗。

SELECT length(content) 看一下content的大小,可能没显示完全!

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。