| 订阅 | 在线投稿
分享
 
 
 

PHP日常实用小Tips

2006-07-20 09:11:34  编辑来源:互联网  国际版  评论
 
 

本文为【PHP日常实用小Tips】的汉字拼音对照版显示拼音

   fuwuqixueyuan1.jianyipanduanipdizhihefaxing

  if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";

  2.emaildezhengzepanduan

  eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);

  3.jianceipdizhihemaskshifouhefadelizi

  $ip = '192.168.0.84';

  $mask = '255.255.255.0';

  $network = '192.168.0';

  $ip = ip2long($ip);

  $mask = ip2long($mask);

  $network = ip2long($network);

  if( ($ip & $mask) == $network) echo "valid ip and maskn";

  ?>

  4.guanyubiaodanshuaxin

  wenweishenmewozaidianjiliulanqidehou退tuianniuhousuoyouziduandexinxidoubeiqingkongle

  dazheshiyouyunizainidebiaodantijiaoyemianzhong使shiyongle session_start hanshugaihanshuhuiqiangzhidangqianyemianbubeihuancunjiejuebanfaweizainide Session_start hanshuhoujiaru header("Cache-control: private"); zhuyizaibenxingzhiqiannidePHPchengxubunengyourenheshuchu

  buchonghuanyoujiyusessiondejiejuefangfazaisession_startqianjiashang

  session_cache_limiter('nocache');// qingkongbiaodan

  session_cache_limiter('private'); //buqingkongbiaodanzhizaisessionshengxiaoqijian

  session_cache_limiter('public'); //buqingkongbiaodanrutongmei使shiyongsessionyiban

  keyizaisession_start();qianjiashangsession_cache_limiter("private,max-age=10800");

  5.kuaisugaodingwenjianxiazaitoubushuchu

  header("Content-type: application/x-download");

  header("Content-Disposition: attachment; filename=$file_download_name;");

  header("Accept-Ranges: bytes");

  header("Content-Length: $download_size");

  echo 'xxx'

  6.yongheadershuchuftpxiazaifangshi,bingqiezhichiduandianxuchuan

  yigelizi:

  header('Pragma: public');

  header('Cache-Control: private');

  header('Cache-Control: no-cache, must-revalidate');

  header('Accept-Ranges: bytes');

  header('Connection: close');

  header("Content-Type: audio/mpeg");

  header("Location:ftp://download:1bk3l4s3k9s2@218.30.116.103/1001/kalilajiao/kalilajiao.rmvb");

  7.zhengzepipeizhongwen

  ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);

  8.piliangtihuanwenbenlimiandechaojilianjie

  function urlParse($str = '')

  {

   if ('' == $str) return $str;

  $types = array("http", "ftp", "https");

  $replace = << ''.htmlentities('1').htmlentities('2').''

  EOPHP;

  $ret = $str;

  while(list(,$type) = each($types))

  {

   $ret = preg_replace("|($type://)([^s]*)|ie ", $replace, $ret);

  }

  return $ret;

  }

  ?>【原文
 
 
 
【 服务器学院】1.简易判断ip地址合法性   if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";   2.email的正则判断   eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);   3.检测ip地址和mask是否合法的例子   $ip = '192.168.0.84';   $mask = '255.255.255.0';   $network = '192.168.0';   $ip = ip2long($ip);   $mask = ip2long($mask);   $network = ip2long($network);   if( ($ip & $mask) == $network) echo "valid ip and maskn";   ?>   4.关于表单刷新   问:为什么我在点击浏览器的后退按钮后,所有字段的信息都被清空了?   答:这是由于你在你的表单提交页面中使用了 session_start 函数。该函数会强制当前页面不被缓存。解决办法为,在你的 Session_start 函数后加入 header("Cache-control: private"); 注意在本行之前你的PHP程序不能有任何输出。   补充:还有基于session的解决方法,在session_start前加上   session_cache_limiter('nocache');// 清空表单   session_cache_limiter('private'); //不清空表单,只在session生效期间   session_cache_limiter('public'); //不清空表单,如同没使用session一般   可以在session_start();前加上session_cache_limiter("private,max-age=10800");   5.快速搞定文件下载头部输出   header("Content-type: application/x-download");   header("Content-Disposition: attachment; filename=$file_download_name;");   header("Accept-Ranges: bytes");   header("Content-Length: $download_size");   echo 'xxx'   6.用header输出ftp下载方式,并且支持断点续传   一个例子:   header('Pragma: public');   header('Cache-Control: private');   header('Cache-Control: no-cache, must-revalidate');   header('Accept-Ranges: bytes');   header('Connection: close');   header("Content-Type: audio/mpeg");   header("Location:ftp://download:1bk3l4s3k9s2@218.30.116.103/1001/咖哩辣椒/咖喱辣椒.rmvb");   7.正则匹配中文   ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);   8.批量替换文本里面的超级链接   function urlParse($str = '')   {    if ('' == $str) return $str;   $types = array("http", "ftp", "https");   $replace = << ''.htmlentities('1').htmlentities('2').''   EOPHP;   $ret = $str;   while(list(,$type) = each($types))   {    $ret = preg_replace("|($type://)([^s]*)|ie ", $replace, $ret);   }   return $ret;   }   ?>
󰈣󰈤
 
 
 
>>返回首页<<
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 
 热帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
©2005- 王朝网络 版权所有