【问题标题】:i want to save scraped content directly to database please correct this我想将抓取的内容直接保存到数据库中,请更正
【发布时间】:2014-05-22 05:51:01
【问题描述】:

我想将抓取的内容直接保存到数据库中,请更正

我只想保存为文本格式,没有密码,只有代码 其他像标题过期(无)都保持不变

<?php
include('simple_html_dom.php');

$code = file_get_html('http://domain.com/')->plaintext; 

$con=mysqli_connect("<dbhost>","<dbuser>","<dbpass>","<dbname>");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$dati = date('Y-m-d H:i:s');

$pid = pid + 1; // 

帮助解决这个问题每个帖子都会增加 pid

mysqli_query($con,"INSERT INTO `paste` (`pid`, `poster`, `posted`, `code`, `parent_pid`, `format`, `codefmt`, `codecss`, `expires`, `expiry_flag`, `password`)
VALUES  ($pid, 'Untitled', $dati, $code, 0, 'text', '<div class="text"><ol><li class="li1"><div class="de1">' . $code . '</div></li>\n</ol></div>', '/**\n * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n * (http://qbnz.com/highlighter/ and http://geshi.org/)\n */\n.text .de1, .text .de2 {font: normal normal 12px monospace; margin:0; padding:0; background:none; vertical-align:top;}\n.text  {font-family:monospace;}\n.text .imp {font-weight: bold; color: red;}\n.text li, .text .li1 {background: #ffffff;}\n.text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}\n.text .li2 {background: #f4f4f4;}\n.text span.xtra { display:block; }\n', NULL, 'f', 'EMPTY')");
?>

【问题讨论】:

  • 1. $code = mysqli_real_escape_string($con,$code) 2. 使用 Prepare 语句为您完成所有这些工作。
  • 不知道你的sql可以插入
    吗?
  • 那么你的代码有什么问题它不起作用?它错过了什么吗?提供更多详细信息和错误消息(如果有)。
  • 是在讨论带自动增量的 PRIMARY 索引吗?阅读thisthis
  • php 复制上一个 msql 行并只更改两个(pid,代码)

标签: php mysql


【解决方案1】:
/*********** Load In Dom *********/
$html = new DOMDocument;
$html->loadHTML($yourTargetHTML);
$xPath = new DOMXPath($html);
/*********** Load In Dom *********/

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签