记下几个有用的函数

来源:互联网 发布:json嵌套json数据 编辑:程序博客网 时间:2024/05/01 22:01

1:fnmatch

array fnmatch ( string pattern, string string [, int flags])

fnmatch() 检查传入的 string 是否匹配给出的 shell 统配符pattern

此函数对于文件名尤其有用,但也可以用于普通的字符串。普通用户可能习惯于 shell 模式或者至少其中最简单的形式 '?''*' 通配符,因此使用 fnmatch() 来代替ereg() 或者preg_match() 来进行前端搜索表达式输入对于非程序员用户更加方便。

例子 1. 用 shell 中的通配符模式匹配来检查颜色

<?php
if(fnmatch("*gr[ae]y",$color)) {
  echo
"some form of gray ...";
}
?>

 

2:strsep

原型:char *strsep(char **stringp, const char *delim);

  功能:分解字符串为一组字符串。从stringp指向的位置起向后扫描,遇到delim指向位置的字符后,将此字符替换为NULL,返回stringp指向的地址。

 

 

3:strcasecmp

函数说明 strcasecmp()用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。
 
 
 
 
 
 
 
 
 
原创粉丝点击