随笔分类 -  function

函数
10个超级有用、必须收藏的PHP代码样例
摘要:作为一个正常的程序员,会好几种语言是十分正常的,相信大部分程序员也都会编写几句PHP程序,如果是WEB程序员,PHP一定是必备的,即使你没用它开发过大型软件项目,也一定多少了解它的语法。 尽管PHP经常被人诟病,被人贬低,被人当玩笑开,事实证明,PHP是全世界网站开发中使用率最高的编程语言。PHP最 阅读全文

posted @ 2016-01-30 10:08 yhdsir 阅读(830) 评论(0) 推荐(0)

yhdsir@function:php
摘要:curl 获取页面信息function curl_get_content($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOP... 阅读全文

posted @ 2015-11-23 00:01 yhdsir 阅读(309) 评论(0) 推荐(0)

javascript常用方法函数收集
摘要:字符串长度截取function cutstr(str, len) { var temp, icount = 0, patrn =/[^\x00-\xff]/, //中文字符 strre = ""; for (var i = 0; i = 0 && thi... 阅读全文

posted @ 2015-07-16 12:55 yhdsir 阅读(232) 评论(0) 推荐(0)

static_func
摘要:<?php function testing() { static $a = 1; $a *= 2; echo $a."\n";}testing(); //2testing(); //4testing(); //8 阅读全文

posted @ 2015-07-15 18:13 yhdsir 阅读(134) 评论(0) 推荐(0)

PHP用星号隐藏部份用户名、身份证、IP、手机号、邮箱等实例
摘要:一、仿淘宝评论购买记录隐藏部分用户名,以下代码亲测可用。function cut_str($string, $sublen, $start = 0, $code = 'UTF-8'){ if($code == 'UTF-8') { $pa = "/[\x01-\x7f]|[... 阅读全文

posted @ 2015-07-15 16:37 yhdsir 阅读(1077) 评论(0) 推荐(0)

参数过滤
摘要:/*** 参数过滤* @param string/array $str * @return string/array */function get_field($str){ if(empty($str)){return;} $string = preg_replace('/selec... 阅读全文

posted @ 2015-07-15 16:26 yhdsir 阅读(318) 评论(0) 推荐(0)

校验是否为手机号码
摘要:/*** 校验是否为手机号码* @param string $mobile* @return boolean*/function is_mobile($mobile) { if(preg_match('#^13[\d]{9}$|14^[0-9]\d{8}|^15[0-9]\d{8}$|^18[0-... 阅读全文

posted @ 2015-07-15 16:08 yhdsir 阅读(510) 评论(0) 推荐(0)

判断是否为邮箱
摘要:/*** 判断是否为邮箱* @param string $email* @param boolean*/function is_email($email) { if(preg_match('/^[0-9a-z_][_.0-9a-z-]{0,32}@([0-9a-z][0-9a-z-]{0,32}\... 阅读全文

posted @ 2015-07-15 16:04 yhdsir 阅读(342) 评论(0) 推荐(0)

生成随机验证码
摘要:/*** 生成随机验证码 * @param string $len 验证码长度* @return string**/function GetRandStr($len) { $chars = array( "0", "1", "2", "3", "4", "5", "6", "7", ... 阅读全文

posted @ 2015-07-15 15:55 yhdsir 阅读(200) 评论(0) 推荐(0)

防止基本的XSS攻击 滤掉HTML标签
摘要:/*** 防止基本的XSS攻击 滤掉HTML标签* 将HTML的特殊字符转换为了HTML实体 htmlentities* 将#和%转换为他们对应的实体符号* 加上了$length参数来限制提交的数据的最大长度*/function transform_HTML($stri... 阅读全文

posted @ 2015-07-15 15:36 yhdsir 阅读(2623) 评论(0) 推荐(0)

预防SQL注入攻击
摘要:/*** 预防SQL注入攻击* @param string $value* @return string*/function check_input($value){ // 去除斜杠 if (get_magic_quotes_gpc()) { $value = stripslash... 阅读全文

posted @ 2015-07-15 15:32 yhdsir 阅读(226) 评论(0) 推荐(0)

导航