一段PHP代码问题
<!-- 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);
<!-- 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.*<\/table>)/iUs', $contents, $match))){ $contents = $match[1][0]; } print_r($contents);
if((preg_match_all('/(<h1.>)/iUs', $contents, $match))){ echo '333'; //测试下是否正则匹配到 $contents = $match[1][0]; var_dump($contents); //打印输出看下 } <br><font color="#e78608">------解决方案--------------------</font><br>网页是<h1>...结构。而 preg_match_all('/(<h1.>)/iUs 等于是匹配全部结构。<br>又 $contents = $match[1][0]; //如果页面仅有一个<h1>... 结构。<br><br>那么。跟file_get_contents()得出的结果不是一样。是什么? <br><font color="#e78608">------解决方案--------------------</font><br>正则表达式有错误,改成:<br>preg_match_all('/<h1>.*/sU', $contents, $match) <br><font color="#e78608">------解决方案--------------------</font><br> preg_match('/<h1.>/is',$str,$m);<br>echo $m[0]; <br><font color="#e78608">------解决方案--------------------</font><br> '">3,3'-二氯联苯胺<a ...></a>你入库的数据没有做转义处理,所以出错<br><br>mediumtext类型最大可存放 16M 字符,应该足够了 <br><font color="#e78608">------解决方案--------------------</font><br> $content=mysql_real_escape_string($contents[0]);<br>$SQL="INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$content}')"; <div class="clear"></div></h1.> </h1> </h1></h1.> </h1></h1.>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号