PHP中的一个while循环
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,2"))){
$string=$rows['pl_title'];
$string1=urlencode($string);
}
echo $string;
$url = "http://localhost/index.php/"."$string1";
$contents = file_get_contents($url);
if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
$contents = $match[1][0];
}
else{
(preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
$contents = $match[1][0];
//echo $match[1][0];
}
<?php $DBserver = "localhost";
$DBname = "wikidb";
$DBuser = "root";
$DBpassword = "";
// mysql 连接,下面代码都将使用这个
$con = mysql_connect("localhost","root","");
mysql_select_db("wikidb");
$query = mysql_query("select pl_title from pagelinks limit 1,3") or die(mysql_error() );
// 更换数据库
mysql_select_db("new", $con);
while ($rows=mysql_fetch_array($query))
{
$string =$rows['pl_title'];
$string1 =urlencode($rows['pl_title']);
// 下面仍是循环的一部分
$url = "http://localhost/index.php/"."$string1";
$contents = file_get_contents($url);
if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
$contents = $match[1][0];
}
else{
preg_match_all('/(<h1.>)/iUs',$contents,$match);
$contents = $match[1][0];
}
// 连接的代码被删除了,你只需要改变连接到的数据库在while上一行
mysql_query("set names 'utf8'");
// 下面两句是什么意思?
// $sql="";
// mysql_query($sql);
$SQL="
INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$contents}')";
// 查询,失败返回错误消息
mysql_query($SQL) or die(mysql_error());
}
// while循环结束
?> <div class="clear"></div></h1.>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号