代码如下 | 复制代码 |
<?php /** * * This class for execute the external program of svn * * @auth Seven Yang http://www.111cn.net * */ class SvnPeer { /** * List directory entries in the repository * * @param string a specific project repository path * @return bool true, if validated successfully, otherwise false */ static public function ls($repository) { $command = "svn ls " . $repository; $output = SvnPeer::runCmd($command); $output = implode("<br>", $output); if (strpos($output, 'non-existent in that revision')) { return false; } return "<br>" . $command . "<br>" . $output; } /** * Duplicate something in working copy or repository, remembering history * * @param $src * @param $dst * @param $comment string specify log message * @return bool true, if copy successfully, otherwise return the error message * * @todo comment need addslashes for svn commit */ static public function copy($src, $dst, $comment) { $command = "svn cp $src $dst -m '$comment'"; $output = SvnPeer::runCmd($command); $output = implode("<br>", $output); if (strpos($output, 'Committed revision')) { return true; } return "<br>" . $command . "<br>" . $output; } /** * Remove files and directories from version control * * @param $url * @return bool true, if delete successfully, otherwise return the error message * * @todo comment need addslashes for svn commit */ static public function delete($url, $comment) { $command = "svn del $url -m '$comment'"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); if (strpos($output, 'Committed revision')) { return true; } return "<br>" . $command . "<br>" . $output; } /** * Move and/or rename something in working copy or repository * * @param $src string trunk path * @param $dst string new branch path * @param $comment string specify log message * @return bool true, if move successfully, otherwise return the error message * * @todo comment need addslashes for svn commit */ static public function move($src, $dst, $comment) { $command = "svn mv $src $dst -m '$comment'"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); if (strpos($output, 'Committed revision')) { return true; } return "<br>" . $command . "<br>" . $output; } /** * Create a new directory under version control * * @param $url string * @param $comment string the svn message * @return bool true, if create successfully, otherwise return the error message * * @todo comment need addslashes for svn commit */ static public function mkdir($url, $comment) { $command = "svn mkdir $url -m '$comment'"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); if (strpos($output, 'Committed revision')) { return true; } return "<br>" . $command . "<br>" . $output; } static public function diff($pathA, $pathB) { $output = SvnPeer::runCmd("svn diff $pathA $pathB"); return implode('<br>', $output); } static public function checkout($url, $dir) { $command = "cd $dir && svn co $url"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); if (strstr($output, 'Checked out revision')) { return true; } return "<br>" . $command . "<br>" . $output; } static public function update($path) { $command = "cd $path && svn up"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); preg_match_all("/[0-9]+/", $output, $ret); if (!$ret[0][0]){ return "<br>" . $command . "<br>" . $output; } return $ret[0][0]; } static public function merge($revision, $url, $dir) { $command = "cd $dir && svn merge -r1:$revision $url"; $output = implode('<br>', SvnPeer::runCmd($command)); if (strstr($output, 'Text conflicts')) { return 'Command: ' . $command .'<br>'. $output; } return true; } static public function commit($dir, $comment) { $command = "cd $dir && svn commit -m'$comment'"; $output = implode('<br>', SvnPeer::runCmd($command)); if (strpos($output, 'Committed revision') || empty($output)) { return true; } return $output; } static public function getStatus($dir) { $command = "cd $dir && svn st"; return SvnPeer::runCmd($command); } static public function hasConflict($dir) { $output = SvnPeer::getStatus($dir); foreach ($output as $line){ if ('C' == substr(trim($line), 0, 1) || ('!' == substr(trim($line), 0, 1))){ return true; } } return false; } /** * Show the log messages for a set of path with XML * * @param path string * @return log message string */ static public function getLog($path) { $command = "svn log $path --xml"; $output = SvnPeer::runCmd($command); return implode('', $output); } static public function getPathRevision($path) { $command = "svn info $path --xml"; $output = SvnPeer::runCmd($command); $string = implode('', $output); $xml = new SimpleXMLElement($string); foreach ($xml->entry[0]->attributes() as $key=>$value){ if ('revision' == $key) { return $value; } } } static public function getHeadRevision($path) { $command = "cd $path && svn up"; $output = SvnPeer::runCmd($command); $output = implode('<br>', $output); preg_match_all("/[0-9]+/", $output, $ret); if (!$ret[0][0]){ return "<br>" . $command . "<br>" . $output; } return $ret[0][0]; } /** * Run a cmd and return result * * @param string command line * @param boolen true need add the svn authentication * @return array the contents of the output that svn execute */ static protected function runCmd($command) { $authCommand = ' --username ' . SVN_USERNAME . ' --password ' . SVN_PASSWORD . ' --no-auth-cache --non-interactive --config-dir '.SVN_CONFIG_DIR.'.subversion'; exec($command . $authCommand . " 2>&1", $output); return $output; } } |
代码如下 | 复制代码 |
<?php $pagesize = 10;//每一页显示多少留言记录 $sql = "SELECT a . * , b.name, b.email, b.qq, c.revert_time, c.revert $recordSql = $sql. " LIMIT ".$page*$pagesize.",".$pagesize; } <body> <tr> post.php文件 <?php $name = $_POST['name']; if($name==""||strlen($name)>10){ //链接数据库 //把客户信息插入guest表 //把以上插入取得的客户id和留言信息插入到post表中 |
下面为后台管理管理的页面 login.php登录先
代码如下 | 复制代码 |
<?php session_start(); if(isset($_POST['Submit'])){ if(!get_magic_quotes_gpc()){ foreach ($_POST as &$items){ $items = addslashes($items); } } if($_POST['username']=='phpiask'&&md5($_POST['password'])=='6dc88b87062a5de19895e952fa290dad'){ $_SESSION['login']=true; echo "<script>alert('管理员登录成功');location.href='index.php';</script>"; exit(); } else { echo "<script>alert('登录失败!');</script>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <table> <tr> <td> <form action="login.php" method="POST" name="form1"> 用户名:<input type="text" name="username" size="20"/> 密码:<input type="password" name="password" size="20"> <input type="submit" value="登录" name="Submit"/> <input type="button" onclick="javascript:location.href='index.php'" value="放弃"/> </form> </td> </tr> </table> </body> </html> |
删除留言的delete.php
代码如下 | 复制代码 |
<?php if(!$_SESSION['login']){ if(isset($_GET['id'])&&$_GET['id']!=""){ |
回复留言的revert.php文件
代码如下 | 复制代码 |
<?php if(!$_SESSION['login']){ |
代码如下 | 复制代码 |
/** |
关于preg_replace()函数语法
preg_replace函数基础与实例代码
//preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) 主题为匹配搜索模式,替换替换
/*
要搜索的模式。它可以是一个字符串或一个字符串数组。
电子修饰符使preg_replace函数()替代治疗后,适当引用作为参数是php教程代码进行替换。提示:请确保置换构成一个有效的php代码字符串,否则php将抱怨在包含preg_replace函数线()解析错误。
返回值
preg_replace函数()返回一个数组,如果这个问题的参数是一个数组或一个字符串,否则。
如果找到匹配,新问题会产生,否则将返回主题不变或null如果发生错误。
更多详细内容请查看:http://www.111cn.net/phper/php-function/33530.htm
在PHP中, 使用我最喜欢的最强大的CURL,嘿嘿
下面是在万网查询域名的实例代码
<?php
$dn = $_GET['dn']; // 域名, 不包括www
$ex = $_GET['ex']; // 顶级域名, 如 .com, .cn, 包括最前面的.
// 查询域名是否已经注册
代码如下 | 复制代码 |
|
下面实例是告诉我们在论坛有看到关于多少秒钟前发了帖子等这些功能,
分析
实际时间 PHP
1秒 2“秒”
______________________
30秒==60
5分钟==60*10 //这里我觉得应该是五分钟,而不是一分钟,个人觉得 一分钟的话应该是 60*2
10分钟==60*20
30分钟==60*60
1小时==60*60*2
2.5小时==60*60*5
原理
用当前时间time(),减去你信息录入时的新增时间,(注意是时间戳),然后得出的差数,就是秒数,再根据自己的需要来转换啊。例如你想转换成分钟,就除以60。
实例
代码如下 | 复制代码 |
<?php $unitArr = array('年' =>'year', '个月'=>'month', '周'=>'week', '天'=>'day', foreach ( $unitArr as $cn => $u ) return $elapse; $past = 2052345678; // Some timestamp in the past echo '发表于' . time2Units($diff) . '前'; |
这是一个刚入门的同学写的
代码如下 | 复制代码 |
<?php list($month1,$day1,$year1) = explode("/",$regist1); $regist1 = mktime(0,0,0,$month1,$day1,$year1); $time_difference = $regist2-$regist1; echo ("时间差:"); |
好了喜欢就自己选择用吧。