PHP字符串教程_trim函数
PHP trim() 函数
定义和用法
trim() 函数从字符串的两端删除空白字符和其他预定义字符。
语法
trim(str,charlist)
参数 1 str为待操作的字符串,参数 2 charlist 可选,指定了想要去除的特殊符号。
如果第二个参数没给值,预设会去除下列这些字元:
" " (ASCII 32 (0x20)), an ordinary space.
"\t" (ASCII 9 (0x09)), a tab.
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
"\0" (ASCII 0 (0x00)), the NUL-byte.
"\x0B" (ASCII 11 (0x0B)), a vertical tab.
如果要去除其它字元,可以在第二个参数里设定。
例子1
<?php
$str = " 使用函数trim去掉字符串两端空白字符 ";
$str1 = trim($str);
echo "处理前有".strlen($str)."个字符";
echo "<br/>"; //www.phpjc.cn
echo "<br/>";
echo "使用trim函数处理后有".strlen($str1)."个字符";
?>
输出:
处理前有39个字符
使用trim函数处理后有34个字符
例子2
<?php
$str = "##使用函数trim去掉字符串两端特定字符####";
$str1 = trim($str,"#"); //为函数trim传入第二个参数,trim将删除字符串$str两端的#字符
echo $str."<br>";
echo $str1;
?>
输出:
##使用函数trim去掉字符串两端特定字符####
使用函数trim去掉字符串两端特定字符
相关文档:
pack/unpack的摸板字符字符含义
format 参数的可能值:
a - NUL-padded string
A - SPACE-padded string
h - Hex string, low nibble first
H - Hex string, high nibble first
c - signed char
C - unsigned char
s - signed short (always 16 bit, machine byte order)
S - unsigned short (always 16 bi ......
打开Editplus,选择工具=》配置用户工具,就用当前的默认组好了。单击“添加工具”选择第一个子项“程序”,取个名字给它,“PhpDebug”吧。在命令中浏览到php.exe的位置,参数选择为“文件路径”,这时我的界面上两个输入框中分别为“D:\usr\php.exe”和&ldquo ......
PHP运行过程
简单点的
浏览器 -> web服务器 -> php解释器 -> mysql服务器 -> php解释器 -> web服务器 -> 浏览器
大家握几个手
复杂点的 浏览器 -----------------------------> web服务器-> php解释器 -> mysql服务器 ….
PHP运行机制
2009-10-20 ......
<?php
function checkMobile($str)
{
$pattern = "/^(13|15)\d{9}$/";
if (preg_match($pattern,$str))
{
Return true;
}
else
{
Return false;
}
}
$str = checkMobile("15800000001");
......
class_exists — 判定一个类是否已经被定义
get_class_methods — 获取某个类中所有方法的名称
get_class_vars — 获取一个类中所有的特性
get_class — 返回一个方法所在的类名
get_declared_classes — 显示已定义的类的信息
get_declared_interfaces — 显示已定义的接口的信息
get ......