echo ccStrLen($str),'<hr>';
echo ccStrLeft($str,3);
function ccStrLeft($str,$len) #从左边截取中英文混合字符串
{
$ascLen=strlen($str); if($ascLen<=$len) return $str;
$hasCC=ereg("[xA1-xFE]",$str); #同上
$hasAsc=ereg("[x01-xA0]",$str);
if(!$hasCC) return substr($str,0,$len);
if(!$hasAsc)
if($len & 0x01) #如果长度是奇数
return substr($str,0,$len+$len-2);
else
return substr($str,0,$len+$len);
$cind=0;$flag=0;
while($cind<$ascLen)
{
if(ord(substr($str,$cind,1))<0xA1) $flag++;
$cind++;
}
if($flag & 0x01)
return substr($str,0,$len);
else
return substr($str,0,$len-1);
}
function ccStrLen($str) #计算中英文混合字符串的长度
{
$ccLen=0;
$ascLen=strlen($str);
$ind=0;
$hasCC=ereg("[xA1-xFE]",$str); #判断是否有汉字
$hasAsc=ereg("[x01-xA0]",$str); #判断是否有ASCII字符
if($hasCC && !$hasAsc) #只有汉字的情况
return strlen($str)/2;
if(!$hasCC && $hasAsc) #只有Ascii字符的情况
return strlen($str);
for($ind=0;$ind<$ascLen;$ind++)
{
if(ord(substr($str,$ind,1))>0xa0)
{
$ccLen++;
$ind++;
}
else
{
$ccLen++;
}
}
return $ccLen;
}
function cs($str)
{
$ccLen=0;
$ascLen=strlen($str);
$ind=0;
for($ind=0;$ind<$ascLen;$ind++)
{
if(ord(substr($str,$ind,1))>0xa0)
{
$ccLen++;
$ind++;
}
else
{
$ccLen++;
}
}
return $ccLen;
}
<?php
$tempquery = mysql_query("select dpb,facejtype from zgy_member_p_d_basic where dpb = '$city' and facejtype like '%$keyword%' ");
$count = mysql_num_rows( $tempquery );
if( $count )
{
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
$pagecount=($count % $pagesize)?(int)($count / $pagesize) +1:$count / $pagesize;
$page=($page>$pagecount || $page<1)?$page=1:$page;
$start=$pagesize*($page-1);
$sql = "Select
dpb,
truename,
uid,
sex,
birth,
education,
experience,
facejkind,
facejtype,
id
from
zgy_member_p_d_basic
where
dpb = '$city' and
facejtype like '%$keyword%' group by uid order by id desc limit $start,$pagesize";
$query = mysql_query( $sql ) or die( mysql_error() );
while( $rs = mysql_fetch_array( $query ) )
{
?>
<tr>
<td><a href="/index.php/display/resume/<?=$rs['id']?>.html" class="col-blu" target="_blank"><?=$rs['truename']?></a></td>
<td>
<?
$date = date("Y-m-d");
$date1 = $rs['birth'];
echo sdate($date,$date1);
?> </td>
<td><?= $rs['sex'] ? '男' : '女' ;?></td>
<td><?= $rs['education']?> </td>
<td><?= $rs['experience']?></td>
<td><?= $rs['facejkind']?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6">
<div class="listPage"><form action="jobs.php?keyword=<?=$keyword?>&city=<?= $city?>" method="get" enctype="application/x-www-form-urlencoded" >总数:<span class="f-red"><?=$count?>/条</span> 每页<?=$pagesize?>条 当前第<span class="f-red"><?=$page?>/<?=$pagecount?></span>页 <a href="jobs.php?keyword=<?=$keyword?>&city=<?= $city?>&page=<?=1?>" class="col-blu"> 首页 </a><a href="jobs.php?keyword=<?=$keyword?>&city=<?= $city?>&page=<?=$page-1;?>" class="col-blu">上一页 </a><span class="col-blu"> <a href="jobs.php?keyword=<?=$keyword?>&city=<?= $city?>&page=<?=$page+1;?>" class="col-blu">下一页 </a></span><a href="#" class="col-blu"><a href="jobs.php?keyword=<?=$keyword?>&city=<?= $city?>&page=<?=$count;?>" class="col-blu">尾页 </a>转到 第
<input name="page" type="text" id="page" size="3" />
<input name="city" type="hidden" value="<?=$city;?>" />
<input name="keyword" type="hidden" value="<?=$keyword;?>" />
页
<input type="submit" name="Submit" value="确定" />
</form>
</div>
</div>
</td>
</tr>
<?
}
else
{
?>
<tr>
<td colspan="6">对不起,您要查找内容暂时不存在!</td>
</tr>
<?php
}
?>
</table>
</div>
<head>
<meta http-equiv="Content-Type" ontent="text/html; charset=gb2312" />
<title>表单元素[select下拉列表]制作二级联动菜单</title>
<?php
$link = mysql_connect('localhost','root','root') or die( mysql_error());
mysql_select_db('cshouse',$link) or die('db error');
mysql_query("set Names'gbk'");
/*$sql = "Select * from zgy_classplace where upid=0 order by id asc";
$result = mysql_query( $sql );
$i =1;
$count = mysql_num_rows( $result );
$b=',';
while( $rs = mysql_fetch_array( $result ) )
{
if( $i==$count ){ $b =''; }
echo " new Array("$rs[id]","$rs[cntitle]")$b nt";
$i++;
}
echo ");";
*/
?>
<script language="javascript">
//下面函数是演示二,联动菜单的处理代码
function makeplace_a(x){
var form2=document.wane_search.one.options.length;//这句解释同上
var wane_searchl=new Array(form2)//新建一个数组,项数为第一个下拉列表的项数
for(i=0;i<form2;i++)//循环第一个下拉列表的项数那么多次
wane_searchl[i]=new Array();//子循环
//下面是给每个循环赋值
var place_a=document.wane_search.place_a;//方便引用
<?php
$sql = "Select * from zgy_classplace where upid=0 ";
$result = mysql_query( $sql );
$j =1;
while( $rs = mysql_fetch_array( $result ) )
{
$sql = mysql_query("Select * from zgy_classplace where upid='$rs[id]' and upid<>0") ;
$i =0;
while( $p =mysql_fetch_array( $sql ) ) {
echo "wane_searchl[$j][$i] = new Option("$p[cntitle]","$p[id]"); nt";
$i++;
}
$j++;
}
?>
for(m=place_a.options.length-1;m>0;m--)
//这个要看清楚,因为要重新填充下拉列表的话必须先清除里面原有的项,清除和增加当然是有区别的了,所以用递减
place_a.options[m]=null;//将该项设置为空,也就等于清除了
for(j=0;j<wane_searchl[x].length;j++){//这个循环是填充下拉列表
place_a.options[j]=new Option(wane_searchl[x][j].text,wane_searchl[x][j].value)
//注意上面这据,列表的当前项等于 新项(数组对象的x,j项的文本为文本,)
}
place_a.options[0].selected=true;//设置被选中的初始值
}
</script>
</head>
<body>
<form id="form20" name="wane_search" method="post" action="">
<select name="one" size="1" onchange="makeplace_a(options.selectedIndex)">
<option value="">---请选择省份---</option>
<?php
$sql_pr = "Select * from zgy_classplace where upid=0";
$result_pr = mysql_query( $sql_pr );
while( $rs_pr = mysql_fetch_array( $result_pr ) )
{
echo "<option value=$rs_pr[id]>$rs_pr[cntitle]</option> nt";
}
?>
</select>
<select name="place_a">
<option value="">---请选择城市---</option>
</select>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
<?php
if($_POST)
{
print_r($_POST);
}
?>
</body>
</html>
php读取远程图片到本地
$message //文章内容
//正则(这个还不是)
$reg = "/<img[^>]*src="(http://(.+)/(.+).(jpg|gif|bmp|bnp))"/isU";
//把抠出来的 img 地址存放到 $img_array 变量中
preg_match_all($reg, $message, $img_array, PREG_PATTERN_ORDER);
//过滤重复的图片
$img_array = array_unique($img_array[1]);
复制代码第二步. 把$img_array 数组循环一下. 做图片保存和文章位置替换 foreach ($img_array as $img){
//判断是否是自己网站上的 图片
if('xxx.com' != get_domain($img)){// 如果这个图片不是自己服务器上的
//读取图片文件
$Gimg = new GetImage();
$Gimg->source = $img;
$Gimg->save_to = './data/temp/';
$FILE = $Gimg->download(); //图片移动到本地
//保存到相册 得到图片保存的位置
$img_path = pic_save($FILE,0,'');
//文本路径替换
$message = str_replace($img, $img_path, $message);
}
}
....这时候 $message 里面已经图片已经替换为自己服务器本地的地址,并且图片也保存到自己的服务器上.
复制代码//下面一个函数 和 类是从网络上找的.
//从url中获得域名
function get_domain($url){
$pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";
preg_match($pattern, $url, $matches);
if(count($matches) > 0) {
return $matches[0];
}else{
$rs = parse_url($url);
$main_url = $rs["host"];
if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {
return $main_url;
}else{
$arr = explode(".",$main_url);
$count=count($arr);
$endArr = array("com","net","org","3322");//com.cn net.cn 等情况
if (in_array($arr[$count-2],$endArr)){
$domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];
}else{
$domain = $arr[$count-2].".".$arr[$count-1];
}
return $domain;
}// end if(!strcmp...)
}// end if(count...)
}// end function
// 从远程吧图片载到服务器本地 的 类
class GetImage {
var $source;
var $save_to;
var $quality;
function download($method = 'curl') {
$info = @GetImageSize($this->source);
$mime = $info['mime'];
// What sort of image?
$type = substr(strrchr($mime, '/'), 1);
switch ($type){
case 'jpeg':
$image_create_func = 'ImageCreateFromJPEG';
$image_save_func = 'ImageJPEG';
$new_image_ext = 'jpg';
// Best Quality: 100
$quality = isSet($this->quality) ? $this->quality : 100;
break;
case 'png':
$image_create_func = 'ImageCreateFromPNG';
$image_save_func = 'ImagePNG';
$new_image_ext = 'png';
// Compression Level: from 0 (no compression) to 9
$quality = isSet($this->quality) ? $this->quality : 0;
break;
case 'bmp':
$image_create_func = 'ImageCreateFromBMP';
$image_save_func = 'ImageBMP';
$new_image_ext = 'bmp';
break;
case 'gif':
$image_create_func = 'ImageCreateFromGIF';
$image_save_func = 'ImageGIF';
$new_image_ext = 'gif';
break;
case 'vnd.wap.wbmp':
$image_create_func = 'ImageCreateFromWBMP';
$image_save_func = 'ImageWBMP';
$new_image_ext = 'bmp';
break;
case 'xbm':
$image_create_func = 'ImageCreateFromXBM';
$image_save_func = 'ImageXBM';
$new_image_ext = 'xbm';
break;
default:
$image_create_func = 'ImageCreateFromJPEG';
$image_save_func = 'ImageJPEG';
$new_image_ext = 'jpg';
}
if(isSet($this->set_extension)){
$ext = strrchr($this->source, ".");
$strlen = strlen($ext);
$new_name = basename(substr($this->source, 0, -$strlen)).'.'.$new_image_ext;
}else{
$new_name = basename($this->source);
}
$save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;
//输出对象 组成跟$_FILE变量一样 得到后自己和平常图片上传处理一样了
$img_info['name'] = basename($this->source);
$img_info['type'] = $mime;
$img_info['size'] = 1000;
$img_info['tmp_name'] = $save_to;
$img_info['error'] = 0;
if($method == 'curl'){
$save_image = $this->LoadImageCURL($save_to);
}elseif($method == 'gd'){
$img = $image_create_func($this->source);
if(isSet($quality)){
$save_image = $image_save_func($img, $save_to, $quality);
}else{
$save_image = $image_save_func($img, $save_to);
}
}
return $img_info;
}
function LoadImageCURL($save_to){
$ch = curl_init($this->source);
$fp = fopen($save_to, "wb");
// set URL and other appropriate options
$options = array(CURLOPT_FILE => $fp,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
}
php 经典的分页函数
/**
*分页函数
*
*
*/
function multi($total, $perPage, $curPage, $pageUrl, $maxPages = 0, $page = 10, $autoGoTo = TRUE, $simple = FALSE) {
$multiPage = '';
$pageUrl .= strpos($pageUrl, '?') ? '&' : '?';
$realPages = 1;
if($total > $perPage) {
$offset = 2;
$realPages = @ceil($total / $perPage);
$pages = $maxPages && $maxPages < $realPages ? $maxPages : $realPages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curPage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curPage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif ($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$multiPage = ($curPage - $offset > 1 && $pages > $page ? '<a href="'.$pageUrl.'page=1" class="first"'.$ajaxtarget.'>1 ...</a>' : '').
($curPage > 1 && !$simple ? '<a href="'.$pageUrl.'page='.($curPage - 1).'" class="prev"'.$ajaxtarget.'>‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multiPage .= $i == $curPage ? '<strong>'.$i.'</strong>' :
'<a href="'.$pageUrl.'page='.$i.($ajaxtarget && $i == $pages && $autoGoTo ? '#' : '').'"'.$ajaxtarget.'>'.$i.'</a>';
}
$multiPage .= ($curPage < $pages && !$simple ? '<a href="'.$pageUrl.'page='.($curPage + 1).'" class="next"'.$ajaxtarget.'>››</a>' : '').
($to < $pages ? '<a href="'.$pageUrl.'page='.$pages.'" class="last"'.$ajaxtarget.'>... '.$realPages.'</a>' : '').
(!$simple && $pages > $page && !$ajaxtarget ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=''.$pageUrl.'page='+this.value; return false;}" /></kbd>' : '');
$multiPage = $multiPage ? '<div class="pages">'.(!$simple ? '<em> '.$total.' </em>' : '').$multiPage.'</div>' : '';
}
$maxpage = $realPages;
return $multiPage;
}
此函数只要传参数就可以有漂亮的分页效果哦,并且支持select下拉设置调转功能