<?
/ / PHP的新闻抓取由Neil Moomey,。
/ /你可以自由的使用此代码作为您的愿望。
/ /请确保您可以从任何网站,你抓从标题许可。
/ /你可能需要写上您的服务器上的标题,文件以加快速度。
/ /抓斗从文件或网页的源代码网站
if(!($myFile=fopen(http://www.111cn.net,"r")))
{
echo "The news interface is down for maintenance.";
exit;
}
while(!feof($myFile))
{
// Read each line and add to $myLine
$myLine.=fgets($myFile,255);
}
fclose($myFile);
/ /解压缩一切的开始和结束之间。您需要包括这些行
/ /在标题或选择一些独特的子在HTML庆祝开始
/ /和新闻结束。
$start="<hr align=";
$end="建立镜像";
$start_position=strpos($myLine, $start);
$end_position=strpos($myLine, $end)+strlen($end);
$length=$end_position-$start_position;
$myLine=substr($myLine, $start_position, $length);
// Display HTML
echo $myLine;
?>
第一个文件名为 phplist.inc
代码如下 | 复制代码 |
<? global $htmlroot; $htmlroot="/web/html"; //"/web/html"是apache的文档根目录,用户可以根据自己的配置修改 ?> |
第二个文件名为 codeshow.php
代码如下 | 复制代码 |
<? highlight_file($filename); //高亮显示文件代码 ?> |
这个是主程序名为 phplist.php
代码如下 | 复制代码 |
<? require ("phplist.inc"); if ($rootpath=="") {$rootpath=$htmlroot;} function filelist($pathname){ //遍历所有的文件和目录,$pathnam为起始目录,$searchs为搜索关键字 global $htmlroot; if (eregi("[/][.][.]$",$pathname)) { $temp=split("[/]",$pathname); $pathname=""; for ($tt=1;$tt<(count($temp)-2);$tt++) $pathname=$pathname."/".$temp[$tt]; } echo $pathname." "; $handle=opendir($pathname); //打开目录 if (@chdir($pathname)) { //cd 进入目录,若无权限则不进入 $file = readdir($handle); //读出所有当前目录下的元素名,第一次读出为‘。’,指上层目录 while ($file = readdir($handle)) { //若有元素就进行以下处理 $fname=$pathname."/".$file; //将元素名与当前目录名结合组成完整的文件名,并赋值给$fname if ((is_file($file)) and (ereg(".php[3]{0,1}$",$file) or ereg(".htm[l]{0,1}$",$file))) //判断是否为文件并且是否以.php和.php3结尾 { $temppp=split($htmlroot,$fname); echo "<a href=$temppp[1]>".$file."</a> ".filesize($file)."bytes <a href=codeshow?filename=$fname><font size=-1>源文件</font></a> "; //findinfile($fname,$searchs); //调用findinfile函数 } elseif (is_dir($fname)) { //判断是否为目录 linkres($fname); //filelist($fname,$searchs);} //递归调用filelist函数 } } chdir(".."); //结束当前递归,返回上层 } closedir($handle); //关闭当前目录读取 } // function linkres($filename){ $tpath=split("/web/html",$filename); $turepath=$tpath[1]; ereg("[^\/~]{0,}$",$filename,$res); //$ft=filetitle($filename); //if ($ft=="") $ft="无标题"; echo "<a href=phplist.php?rootpath=$filename>".$res[0]."</a> <dir> "; } // filelist($rootpath); |
?>
本文章提供这一款php mysql 分页代码与分页代码是一款从创建数据库与查询数据到把数据进行分页,比较适合于php初学者,并且这款分页代码实用简单容易。<?
/*存放贴子的表结构------------------------------------------------------
代码如下 | 复制代码 |
create table bbsrow( bbsrow_id int(6) not null auto_increment, //贴子ID号 bbsrow_auth varchar(20) not null, //贴子作者 bbsrow_parentid int(6), //贴子的父亲贴子ID号,如为首发贴则为空 bbsrow_title varchar(200) not null, //贴子标题 bbsrow_returncount int(3), //贴子的回复贴数,如果没有回贴则为空 primary key (bbsrow_id) |
);
-----------------------------------------------------------------------------*/
//显示儿子贴的递归函数--------------------------------------------------
代码如下 | 复制代码 |
function showchildren($parent_id){ global $connect_id; $query="select * from bbsrow where bbsrow_parentid='" . $parent_id . "'"; $result_top=mysql_query($query,$connect_id); echo "<ul> "; while($myrow_child=mysql_fetch_row($result_top)){ echo "<li>"; echo $myrow_child[0]; echo $myrow_child[1]; echo $myrow_child[2]; echo $myrow_child[3]; echo $myrow_child[4] . " "; //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴 if($myrow_child[4]!=''){ showchildren($myrow_child[0]); } } echo "</ul>"; } |
//----------------------------------------------------------------------
//连接数据库并将所有首发贴放到$mainrow数组里----------------------------
代码如下 | 复制代码 |
$connect_id=mysql_connect("localhost","test","test") or die("无法连接数据库"); $i=0; //开始构建分页显示------------------------------------------------------ if($currentpage!=""){ $pagesize=10;//每页显示的首发贴数!
if($page>0) $pagestr="<a href=bbsrow.php4?currentpage=" . ($page-1) . ">上一页</a>"; for($i=0;$i<$totalpage;$i++){ $pagestr=$pagestr . "页]"; if($page<$totalpage-1) $pagestr=$pagestr . "<a href=bbsrow.php4?currentpage=" . ($page+1) .">下一页</a><p> "; echo $pagestr; |
//----------------------------------------------------------------------
//开始分级显示----------------------------------------------------------
代码如下 | 复制代码 |
echo "<ul> "; for($i=$start;$i<$end;$i++){ echo "<li> "; echo $mainrow[$i][0]; echo $mainrow[$i][1]; echo $mainrow[$i][2]; echo $mainrow[$i][3]; echo $mainrow[$i][4] . " "; //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴 if($mainrow[$i][4]!=''){ showchildren($mainrow[$i][0]); } } echo "</ul> "; |
//----------------------------------------------------------------------?>
ServerName www.111cn.net
ServerAlias *.111cn.net 111cn.net
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((?!www)w)+.111cn.net$
RewriteRule ^/?$ /domainAction.action?subDomain=%0 [L,PT]
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
$_POST['username'] = $username;
$_POST['admin'] = $admin;
$_POST['gender'] = $gender;
$_POST['address'] = $address;
$_POST['hometel'] = $hometel;
$_POST['hp'] = $hp;
$_POST['email'] = $email;
$_POST['course'] = $course;
$_POST['year'] = $year;
$_POST['path'] = $path;
$_POST['title'] = $title;
$_POST['supervisor'] = $supervisor;
echo "Data has been submitted";
function Enter_New_Entry($username,$admin,$gender,$address,$phone,$hp,$email,$cou rse,$year,$path,$title,$supervisor) {
if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection");
$SQL_Exec_String = "Insert Into rank (username,admin,gender,address,hometel,hp,email,course,year,path,title,s upervisor)
Values ('$username','$admin','$gender','$address','$phone','$hp','$email','$cou rse','$year','$path','$title','$supervisor')";
$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}
odbc_close( $cnx);
}
Enter_New_Entry($username,$admin);
?>
</body>
</html>