<?php
//数据库处理类
class db
{
//SQL执行后的数据保存变量;
var $db;
//读取或设置当前数据的位置
var $position=0;
//执行SQL语句并把结果保存为db变量中;
<?php
//数据库处理类
class db
{
//SQL执行后的数据保存变量;
var $db;
//读取或设置当前数据的位置
var $position=0;
//执行SQL语句并把结果保存为db变量中;
先看一个php与mysql数据库的无限分类
建立数据库 :
id,fid,fname(id和fid都必需是数字类型而且fid的默认值一定要设成0;
<?php
// Adam's Custom PHP MySQL Pagination Tutorial and Script
// You have to put your mysql connection data and alter the SQL queries(both queries)
// This script is in tutorial form and is accompanied by the following video:
mysql_connect("DB_Host_Here","DB_Username_Here","DB_Password_Here") or die (mysql_error());
mysql_select_db("DB_Name_Here") or die (mysql_error());
////////////// QUERY THE MEMBER DATA INITIALLY LIKE YOU NORMALLY WOULD
$sql = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC");
//////////////////////////////////// Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////
$nr = mysql_num_rows($sql); // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
//$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
$pn = 1;
}
//This is where we set how many database items to show on each page
$itemsPerPage = 10;
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
$pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
$pn = $lastPage; // force it to be $lastpage's value
}
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
} else if ($pn == $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> ';
} else if ($pn > 1 && $pn < $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC $limit");
//////////////////////////////// END Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
// This shows the user what page they are on, and the total number of pages
$paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' ';
// If we are not on page 1 we can place the Back button
if ($pn != 1) {
$previous = $pn - 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
}
// Lay in the clickable numbers display here between the Back and Next links
$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
// If we are not on the very last page we can place the Next button
if ($pn != $lastPage) {
$nextPage = $pn + 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
}
}
///////////////////////////////////// END Adam's Pagination Display Setup ///////////////////////////////////////////////////////////////////////////
// Build the Output Section Here
$outputList = '';
while($row = mysql_fetch_array($sql2)){
简单的mysql数据表结构
CREATE TABLE messages
(
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(150)
);
汉字转换成unicode方法
<?php
//将utf8编码的汉字转换为unicode
function htou($c){
$n = (ord($c[0]) & 0x1f) << 12;
$n = (ord($c[1]) & 0x3f) << 6;
$n = ord($c[2]) & 0x3f;
return $n;
}
1) 修改 php 扩展代码以兼容支持 php 5.4.x
2) 修正 php 扩展中 scws_get_tops 的 limit 参数不允许少于 10 的问题
3) libscws 增加 scws_fork() 从既有的 scws 实例产生分支并共享词典/规则集,主要用于多线程开发。
4) 新增部分版本的 win32 的 dll 扩展
方法一:
用serialize写入,再用unserialize输出
利用以上汉字与英文的差异,我们就可以利用mb_strlen函数与strlen函数分别计算出两组长度数字,然后根据规律进行运算即可判断出字符串的类型了
先讲一下strlen与mb_strlen是求字符串长度的函数
1,不做总长度判断,长度判断可以自己加上;
2,支持.net.cn,.com.cn这样的域名后缀;
<?php
/**
* PHP获取一组随机数字不重复
*/
$a = microtime();
function createRandID($m){
// 产生一个从1到$m的数组
$arr = range(1,$m);
// 打乱数组
shuffle ($arr);
// 取前十个
for($i=0;$i<=10;$i++){
// 赋值给新数组$n
$n[] = $arr[$i];
}
// 返回这组数字
return implode($n,',');
}
echo createRandID(700000);
echo '<br />';
echo $a - microtime();
?>
假如脚本路径下有如下文件
-bash-4.1# ll
总用量 12
-rw-rw-r--. 1 www web 133 7月 16 15:00 a.php
-rw-r--r--. 1 lee web 59 2月 29 17:05 b.php
-rw-r--r--. 1 lee web 81 3月 8 17:00 c.php
ob_start ob_get_flush 这些函数是缓存技术的一种,是减轻服务器压力的,直到项目开发用到才知道混淆了和缓存的概念,
这些像ob_start ob_get_flush这些函数都是为了在编程中字符串输出到客户端上去为了延长时间而用到的技术,延迟输出(字符串先发送到缓冲区需要时在输出到浏览器),是一种输出技巧。最常见的应用是静态化技术(可以实现静态缓存):