【问题标题】:why would this text is stored as empty in a text mysql field为什么此文本会在文本 mysql 字段中存储为空
【发布时间】:2011-09-23 11:48:33
【问题描述】:
%3Cimg+src%3D%27http%3A%2F%2Fmnmstatic.net%2Fcache%2F15%2F15%2Fthumb-1381820.jpg%27+width%3D%2760%27+height%3D%2760%27+alt%3D%27%27+class%3D%27thumbnail%27+style%3D%27float%3Aright%3Bmargin-left%3A+3px%27+align%3D%27right%27+hspace%3D%273%27%2F%3E%3Cp%3EAunque+se+haya+dado+marcha+atr%C3%A1s%2C+lo+que+ha+ocurrido+en+RTVE+es+muy+serio.+Seg%C3%BAn+Gabilondo%2C+este+asunto+nos+permite+ver+con+claridad+por+d%C3%B3nde+va+la+pol%C3%ADtica+y+por+d%C3%B3nde+va+el+pensamiento+del+PP+entorno+a+la+libertad+de+informaci%C3%B3n.%3C%2Fp%3E%3Cp%3E%3Cstrong%3Eetiquetas%3C%2Fstrong%3E%3A+tve%2C+i%C3%B1aki+gabilondo%3C%2Fp%3E%3Cp%3E%3Ca+href%3D%22http%3A%2F%2Fmenea.me%2Ftm7w%22%3E%3Cimg+src%3D%22http%3A%2F
%2Fwww.meneame.net%2Fbackend%2Fvote_com_img.php%3Fid%3D1381820%22+alt%3D%22votes%22+width
%3D%22200%22+height%3D%2216%22%2F%3E%3C%2Fa%3E%3C%2Fp%3E%3Cp%3E%26%23187%3B%26nbsp%3B%3Ca+href%3D%22http%3A%2F%2Fblogs.cadenaser.com%2Fla-voz-de-inaki%2F2011%2F09%2F23%2Ftve-acorralada%2F%22+onmousedown%3D%22this.href%3D%27http%3A%2F%2Fwww.meneame.net%2Fbackend%2Fgo.php%3Fid%3D1381820%27%3B+return+true%22+%3Enoticia+original%3C%2Fa%3E%3C%2Fp%3E

这将是包含 RSS 文件 $item->description 的文本,我试图将其存储在我的 MySQL 数据库中,但它存储了一个空字符串。

此文本示例位于echo 下,就在$mysql 查询之前。

是不是因为前面有%3C

完整的脚本是:

$filename = "http://www.ofertasybonos.com/blog/?feed=rss2";
$feed = simplexml_load_file($filename);

//  Iterate through the list and create the unordered list
$n = false;
foreach ($feed->channel->item as $item) {
            $user       = "ofertasybonos";
            $pass       = "ofertasybono";
            $title = urlencode($item->title);
            if(strlen($item->description)>6000){
     $notes = urlencode(substr($item->description, 6000).'..' );
}else{
     $notes = urlencode($item->description);
}
            $url = urlencode($item->link);
            $tags = ''; $tags .= urlencode(urlencode($item->category)); if($tags=='')  $tags = urlencode("ofertas, bonos");

            $params = "nombre=$user&pass=$pass&url=$url&tags=$tags&notes=$notes&title=$title";

            $res = file_get_contents ("http://domain.com/API/public/autosave.php?$params");
            /*this file getContents stores in database*/


    $n = true;
}


this is how is (supoused to be) stored

接收数据表单 file_get_contents

$texto = urldecode($_GET['notes']);

存储在数据库中

$insert = "INSERT INTO links (nombre, coment, url, iduser,fecha,priv)
                               VALUES ('$b','$r_int','$texto ','$id_tmp',NOW(),'$priv')";

知道为什么文本存储为空吗?

【问题讨论】:

  • 存储和检索该字符串的代码在哪里?
  • 既然你已经验证了字符串是正确的,问题可能在于你如何将它存储在数据库中,所以你应该在你的问题中包含 MySQL 代码。
  • %3C<,在MySQL中没有任何特殊含义。 % 确实有特殊含义,它是一个通配符,我认为它需要用 ` like so: '\%3C.....` 为每个 '%' 转义。
  • 您没有包含实际将数据存储在数据库中的代码,也包含该代码。
  • $_GET、mysql_real_escape 和插入。一直都是这样;曾经工作。我确定它改变了它的 RSS 内容

标签: php mysql string rss file-get-contents


【解决方案1】:

我不知道这是否是正确的解决方案,但如果你尝试序列化数据?

序列化数据的方法是 serialize(); http://php.net/manual/en/function.serialize.php 反序列化数据的方法是 unserialize(); http://www.php.net/manual/en/function.unserialize.php

【讨论】:

    【解决方案2】:

    你在 texto 前面忘记了 $

    $insert = "INSERT INTO links (nombre, coment, url, iduser,fecha,priv) VALUES ('$b','$r_int','$texto','$id_tmp',NOW(),'$priv')";

    【讨论】:

    • aha.. 是的,但它仅在我的 .php 文件中的问题中很好,已编辑:谢谢和抱歉
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多