一些使用频率比较高的PHP函数
2013-09-04 21:45
399 查看
在php开发中,我们经常会遇到一些函数,下面是整理好的,可以直接使用,方便开发效率,不过建议大家一定要先看懂,然后在这个基础上增加功能就提高了自身能力了
1.产生随机字符串函数
function random($length) {$hash = @#@#;$chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#;$max = strlen($chars) - 1;mt_srand((double)microtime() * 1000000);for($i = 0; $i < $length; $i++) {$hash .= $chars[mt_rand(0, $max)];}return $hash;}2.截取一定长度的字符串
注:该函数对gb2312使用有效
function wordscut($string, $length ,$sss=0) {if(strlen($string) > $length) {if($sss){$length=$length - 3;$addstr=@# ...@#;}for($i = 0; $i < $length; $i++) {if(ord($string[$i]) > 127) {$wordscut .= $string[$i].$string[$i + 1];$i++;} else {$wordscut .= $string[$i];}}return $wordscut.$addstr;}return $string;}3.取得客户端ip地址
function getip(){if (getenv("http_client_ip") && strcasecmp(getenv("http_client_ip"), "unknown"))$ip = getenv("http_client_ip");else if (getenv("http_x_forwarded_for") && strcasecmp(getenv("http_x_forwarded_for"), "unknown"))$ip = getenv("http_x_forwarded_for");else if (getenv("remote_addr") && strcasecmp(getenv("remote_addr"), "unknown"))$ip = getenv("remote_addr");else if (isset($_server[@#remote_addr@#]) && $_server[@#remote_addr@#] && strcasecmp($_server[@#remote_addr@#], "unknown"))$ip = $_server[@#remote_addr@#];else$ip = "unknown";return($ip);}4.创建相应的文件夹
function createdir($dir=@#@#){if (!is_dir($dir)){$temp = explode(@#/@#,$dir);$cur_dir = @#@#;for($i=0;$i5.判断邮箱地址
function checkemail($inaddress){return (ereg("^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+",$inaddress));}6.跳转
function gotourl(
1.产生随机字符串函数
function random($length) {$hash = @#@#;$chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#;$max = strlen($chars) - 1;mt_srand((double)microtime() * 1000000);for($i = 0; $i < $length; $i++) {$hash .= $chars[mt_rand(0, $max)];}return $hash;}2.截取一定长度的字符串
注:该函数对gb2312使用有效
function wordscut($string, $length ,$sss=0) {if(strlen($string) > $length) {if($sss){$length=$length - 3;$addstr=@# ...@#;}for($i = 0; $i < $length; $i++) {if(ord($string[$i]) > 127) {$wordscut .= $string[$i].$string[$i + 1];$i++;} else {$wordscut .= $string[$i];}}return $wordscut.$addstr;}return $string;}3.取得客户端ip地址
function getip(){if (getenv("http_client_ip") && strcasecmp(getenv("http_client_ip"), "unknown"))$ip = getenv("http_client_ip");else if (getenv("http_x_forwarded_for") && strcasecmp(getenv("http_x_forwarded_for"), "unknown"))$ip = getenv("http_x_forwarded_for");else if (getenv("remote_addr") && strcasecmp(getenv("remote_addr"), "unknown"))$ip = getenv("remote_addr");else if (isset($_server[@#remote_addr@#]) && $_server[@#remote_addr@#] && strcasecmp($_server[@#remote_addr@#], "unknown"))$ip = $_server[@#remote_addr@#];else$ip = "unknown";return($ip);}4.创建相应的文件夹
function createdir($dir=@#@#){if (!is_dir($dir)){$temp = explode(@#/@#,$dir);$cur_dir = @#@#;for($i=0;$i5.判断邮箱地址
function checkemail($inaddress){return (ereg("^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+",$inaddress));}6.跳转
function gotourl(
相关文章推荐
- 一些使用频率比较高的PHP函数
- 这是一些使用频率比较高的PHP函数
- 这是一些使用频率比较高的php函数......
- 一些使用频率比较高的php函数
- 一些使用频率比较高的php函数
- 【整理】前端中使用频率比较高的一些知识点。
- 汇总:一些不错的使用频率比较高的JS函数
- 使用频率比较高的PHP函数方法
- 使用频率比较高的PHP函数方法
- 汇总:一些不错的使用频率比较高的JS函数
- 很不错的使用频率比较高的JS函数
- NGUI研究之开发项目的一些使用心得比较细节
- 以通过修改注册表,让键盘上一些使用频率不高的键来充当音量控制按键
- 一、功能简述 正是微博如火如荼的时节,其中各个微博的分享功能是网站推广产品的好东东啊,此时如何方便快捷的使用微博的分享功能就显得比较重要了。我的站点每篇文章的底部有一些分享的链接: 不过我觉得这些分享
- SAP ABAP开发者 使用频率比较高的事务码
- Android 当前比较新的框架组合,Retrofit,OKHttp,RXJava的一些简单使用
- (水文,内容比较初级,高手勿进)使用SVN版本控制之后常见的一些问题01
- Oracle SQLPlus 一些使用经验记录(设置环境变量和字符串比较)
- java collection framework 的一些比较使用的记录
- 一些比较常用的在Markdown使用的数学符号