php 字符串的一些操作,以便记忆

php 字符串的操作

  • trim($str,'特殊字符')-----去除字符串左右两边的字符,返回字符串
  • ltrim(),rtrim()--------------------左,由两边,与trim()类似;
  • addslashes($str)--------------为字符串加入斜线,两侧,返回字符串
  • stripslashes($str)-------------将addslashes()的字符返回原样
  • strlen($str)-----------------------返回长度
  • substrate(string str,int start[,int length)-------------截取从stat开始,长度为length的字符串
  • strcmp(string str1,string str2)------比较字符串大小,区分大小写,返回值1,0,1
  • strcasecmp(string str1,string str2)----比较大小,不区分大小写,返回值1,0,1
  • strnatcmp(string str1,string str2)-------自然排序法,区分大小写
  • strncmp(string str1,string str2,int len)-比较字符串中长度为len的字符
  • strstr(string haystack,string needle)-返回needdle在haystack首次出现的位置到末尾的子字符串
  • str_ireplace(mix search,mix replace,mix subject[,int&count]),用replace替换subject中search,count代表替换次数)
  • substr_replace(string str,string repl,int start,[int length])--用repl代替str中他位置开始长度为count的字符串
  • explode('拆分',str);
  • impode('区分',arr);
原文地址:https://www.cnblogs.com/ITcore/p/5428417.html