函数代码:复制代码 代码如下://php 批量过滤post,get敏感数据 if (get_magic_quotes_gpc()) { $_GET = stripslashes_array($_GET); $_POST = stripslashes_array($_POST); } function stripslashes_array(&$array) { while(list($key,$var) = each($array)) { if ($key != ‘argc‘ && $key != ‘argv‘ && (strtoupper($key) != $key || ‘‘.intval($key) == "$key")) { if (is_string($var)) { $array[$key] = stripslashes($v...
与PHP字符串转义相关的配置和函数如下: 1.magic_quotes_runtime 2.magic_quotes_gpc 3.addslashes()和stripslashes() 4.mysql_escape_string() 5.addcslashes()和stripcslashes() 6.htmlentities() 和html_entity_decode() 7.htmlspecialchars()和htmlspecialchars_decode() 当magic_quotes_runtime打开时,php的大部分函数自动的给从外部引入的(包括数据库或者文件)数据中的溢出字符加上反斜线。 可以使用set_magic_quotes_runti...
我们可以用header来定义一个php页面为utf编码或GBK编码,也可以在html中用meta标签来指定编码例如:php页面为utf编码 header("Content-type: text/html; charset=utf-8");我们通常使用header或meta,下面说一说两者的区别 一、采用meta页面编码 用meta来设置页面编码1<meta http-equiv="content-type" content="text/html; charset=编码类型"> 作用是:声明客户端的浏览器用什么字符集编码显示该页面,起到通知浏览器的作用。...
<?php
/*
定义和用法
substr() 函数返回提取的子字符串, 或者在失败时返回 FALSE。语法
substr(string,start,length)参数 描述
string 必需。规定要返回其中一部分的字符串。
start
必需。规定在字符串的何处开始。
非负数 - 从 string 的 start 位置开始,从 0 开始计算.
负数 - 从 string 结尾处向前数第 start 个字符开始。
如果 string 的长度小于或等于 start,将返回 FALSE。length
可选。规定要返回的字符串长度。默认是...
$str="你好<我>(爱)[北京]{天安门}";
echo f1($str); //返回你好 echo f2($str); //返回我 echo f3($str); //返回爱 echo f4($str); //返回北京 echo f5($str); //返回天安门function f1($str)
{
$result = array();
preg_match_all("/^(.*)(?:<)/i",$str, $result);
return$result[1][0];
} function f2($str)
{
$result = array();
preg_match_all("/(?:<)(.*)(?:>)/i",$str, $result);
return$result[1][0];
}
functi...
在PHP中偶尔遇到字符串的压缩,比如一个长字符串,数据库开始设计的字段存不下,但是又不想改数据库字段存储长度,就可以用压缩的方式降低数据字段字符串的长度数量级,把几百个字符的字符串压缩到几十个字符。总结下来有以下几个:压缩函数:gzcompress gzdeflate gzencode与之对应的解压函数如下:解压函数:gzuncompress gzinflate gzdecode特别注意:gzdecode是PHP 5.4.0之后才加入的,使用的时候要注意兼容性问题。gzcompress...
使用“===”来判断,至于它和“==”的区别,简单来说就是前者强调“identical(相同的,完全相同)”类型也要求一样;后者要求“equal(相等)”,值相同就可以了。或者使用strcmp来判断,但是这个能够告诉你两个字符串是否相等,但是无法告诉你在哪里不同。一般能用 !=, == 比较两个对象是否相等,之所以说是两个对象,是因为他们不一定全部为字符串,也能为整型等等。比如复制代码 代码如下:$a = "joe"; $b = "jerry"; if ($a != $...
先来个函数,是最近WordPress 3.6中刚刚引入的/*** Add slashes to a string or array of strings.** This should be used when preparing data for core API that expects slashed data.* This should not be used to escape data going directly into an SQL query.** @since 3.6.0** @param string|array $value String or array of strings to slash.* @return string|array Slashed $value*/
function wp_slash( $value ) {if...
eval(phpcode)eval() 函数把字符串按照 PHP 代码来计算。相当于在字符串两边分别加上PHP语法标签该字符串必须是合法的 PHP 代码,且必须以分号结尾。如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false。<?php$string = "beautiful";$time = "winter";$str = ‘This is a $string $time morning!‘;echo $str. "<br />"; // This is a $string $time morning!eval("\$str = ...
<?php//strlen("aaa");取字符串的长度 ***echostrlen("aaaaa");echo "<br />";//$array = explode("|",$s);拆分字符串,返回一个字符串的数组 ***$str1="aaaa|bbb|cc|d";$array1=explode("|",$str1);print_r($array1);echo "<br />";print_r(explode("|",$str1));echo "<br />";//$s = substr($s,4,10);截取字符串,根据开始位置结束位置截取 ***$str2="hello world";echosubstr($str2,2,3); echo "<br />"; //strcmp("aaa","aaa")...
字符串截取在php开发中是比较常用的;而且对于截取的需求也有很多种;就比如说对url链接的操作:http://www.baijunyao.com/index.php/Home/Index/article/aid/12有时我们想截取最后一个斜杠‘/‘后面的数字;有时我们又需要截取第一个斜杠‘/‘前面的内容判断用户输入的url链接带不带http://等等;字符串的截取php内置函数就有很多种;简单的写几个示例;1$str=‘123/456/789/abc‘;截取第一个斜杠前面的内容可以这样来:1echo sub...
这是一个获取字符串中两个子串之间的子串,如从字符串www.jb51.net中获取coderbolg子串,就让这个PHP函数来实现吧,代码如下:复制代码 代码如下:
function get_between($input, $start, $end) {
$substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1)); return $substr;}$string = "www.jb51.net";$start = "www.";$end = ".net";echo get_between($string, $start,...
一.从后台传过来的json不做处理,前端result.name这样调用回乱码。应该使用urldecode将jsonencod转码注意json只接受utf-8编码的字符,所以json_encode()的参数必须是utf-8编码,否则会得到空字符或者null。后台:if(!empty($chatData)){ echo urldecode(json_encode($chatData)); <?php $testJSON=array(‘name‘=>‘中文字符串‘,‘value‘=>‘test‘); //echo json_encode($testJSON); foreach ( $testJSON as $k...
?12345678910111213<?php$b=‘12‘;$a=<<<sss<html> <head> </head> <body> <i><b>{$b}</b></i> </body></html>sss; echo$a;?> 原文:http://www.cnblogs.com/zuoxiaobing/p/3649332.html
在thinkphp中同样可以用 explode来进行字符的切割工作,比如 $jihe=‘1,2,3,4‘;在使用explode之后,可以获得一个数组:$array=explode(‘,‘,$jihe);输出内容如下:Array ([0] => 1[1] => 2[2] =>3[3] => 4)此时可以用计数函数来计算一共分割出来几个数$count=count($array);结果为:4另外发现,如果一开始 $jihe 的值为空,经过explode 之后,再计数也会是 1,可能是因为会获得一个空值数组所以count后是 1吗?待考证。此时就需要...