php in_array 和 str_replace】的更多相关文章

有这样的用法哦 $allow_state_array_invoc = array('store_invoice','invoiceno','invoicerec','invoiceing'); if (in_array($_GET['state'],$allow_state_array_invoc)) { $condition['invoice_state'] = str_replace($allow_state_array_invoc, array('0','1','2','3'), $_GE…
先把今天要用的几个函数罗列出来: //explode()转换成数组,implode()转化成字符串 explode("分隔符",需要被分割的字符串或变量) $priv="product,index"; explode(",",$priv); //判断一个字符串是否存在于一个数组中 in_array(被判断的,数组) $now_page="index"; in_array($now_page,$priv); //将数组用分隔符分…
可参考上篇文章  链接 PHP数组简写模式 同样是PHP版本问题:in_array()函数 第二个参数应该为数组 但是 lnmp下,PHP5.3不报错,wamp下PHP5.5报以下错误: echo "<br>For in_array:"; $arrstr="weibhd1"; if(in_array("weibhd1",$arrstr)) { echo "ok!"; }else{ echo "no!&qu…
写一个数组里面有小写a-z 大写A-Z 以及数字,把相似的数字和字母都剔除     无论大小写:将括号内的数字剔除(0,o,2,Z,1,i) $arr1 = range("a", "z"); $arr2 = range("A","Z"); $arr3 = range(,); $arr4 = [,,,"i","I"]; // 方法一: $arr=array_merge($arr1,$arr…
自己写的一段: //gool char* str_replace(char* source, const char* find, const char* replace){ if (source == NULL || find == NULL || find == "") return strdup(source); int matchCount = 0; int nowIndex = 0; int findLength = strlen(find); int replaceLengt…
(一)strtr是字符替换函数 (1)单个字符替换: <?php echo strtr("abba", "ab", "10"),"\n"; echo strtr("baab", "ab", "01"),"\n"; ?> 输出结果为: (2)字符串对应替换: <?php $trans = array("ab" =…
转自:http://benchmarks.ro/2011/02/str_replace-vs-preg_replace/ 事实证明str_replace确实比preg_replace快. If you find yourself handling strings and replacing sub-strings within them you want to make sure that you are using the fastest way possible to do it.In or…
in_array函数是判断数据中是否存在指定的内容了,对于这个函数用法非常的简单但在使用过程中会我发现有一些问题. 先介绍一下需求背景: 发票方式: 0=捐赠(不要问我为什么,历史原因) 1=对中寄送 2=索取 3=电子发票 现在要对用户提交的数据进行检测: php;auto-links:false;">if(!in_array($_POST['invoice_action'], array(0,1,2,32881064151))){ throw new Exception('请选择正确的…
语法 str_replace(find,replace,string,count) 参数 描述 find 必需.规定要查找的值. replace 必需.规定替换 find 中的值的值. string 必需.规定被搜索的字符串. count 可选.一个变量,对替换数进行计数. 这个我不确定是语法bug还是我写法的问题,当出现匹配字符出现一个在第一匹配选项的时候,会出现不完全匹配的情况,导致匹配出的字符有问题 $list = str_replace(array(0,10,20,30,40), arr…
<php    /**    * 安全过滤函数    *    * @param $string    * @return string    */    function safe_replace($string) {    $string = str_replace('%20','',$string);    $string = str_replace('%27','',$string);    $string = str_replace('%2527','',$string);    $s…