• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

一段PHP代码有关问题

php 搞代码 3年前 (2022-01-23) 11次浏览 已收录 0个评论

一段PHP代码问题

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$url = "http://localhost/index.php/"."$string1";       $contents = file_get_contents($url);print_r($contents);    
PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    $url = "http://localhost/index.php/"."$string1";       $contents = file_get_contents($url);//print_r($contents);              if((preg_match_all('/(<h1>)/iUs', $contents, $match))){        $contents = $match[1][0];    }print_r($contents);

为什么这2段代码打印出的结果是一样的啊,这个网页是

结构的啊,其他类似的能成功截取,就是这个网页打印出的结果和没截取是一样的。。。

——解决方案——————–
给出你的页面内容才行呀,这样子你让人怎么猜? 有问题的肯定就是在正则咯
——解决方案——————–
第二段正则的地方输出看下

PHP code

   if((preg_match_all('/(

)/iUs', $contents, $match))){ echo '333'; //测试下是否正则匹配到 $contents = $match[1][0]; var_dump($contents); //打印输出看下 }
------解决方案--------------------
网页是

...

结构。而 preg_match_all('/(

)/iUs 等于是匹配全部结构。本@文来源[email protected]搞@^&代*@码网(搞代gaodaima码
又 $contents = $match[1][0]; //如果页面仅有一个

...

结构。

那么。跟file_get_contents()得出的结果不是一样。是什么?
------解决方案--------------------
正则表达式有错误,改成:
preg_match_all('/

.*<\/table>/sU', $contents, $match)
------解决方案--------------------
preg_match('/

/is',$str,$m);
echo $m[0];
------解决方案--------------------
'">3,3'-二氯联苯胺你入库的数据没有做转义处理,所以出错

mediumtext类型最大可存放 16M 字符,应该足够了
------解决方案--------------------
$content=mysql_real_escape_string($contents[0]);
$SQL="INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$content}')";


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一段PHP代码有关问题

喜欢 (0)
[搞代码]
分享 (0)

发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址