欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-07 11:06:28
...
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('/(
){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());

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

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

回复内容:

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('/(
){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());

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

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

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

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