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

WBOY
Release: 2016-06-06 20:28:03
Original
1110 people have browsed it

<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>
Copy after login
Copy after login

我是把项目放在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>
Copy after login
Copy after login

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

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

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

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

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