返回列表 发帖

PHP常用字符串操作函数

1)截断
substr("abcd", 0, 2);  // ab

2)替换
$Content = str_replace('<br>', '<p>', $Content) // 将Content里的<br>替换为<p>
str_ireplace 忽略大小写
正则表达式替换
$str = preg_replace('/\<.+?\>/','',$str); // 将str中的HTML标记清空

3)字符集转换
$keyword=iconv("GBK","UTF-8",$keyword); //转换为utf-8

4)字符串查找
strpos("abcde", "cd");

5)变量是否存在
if(isset($x))
  //存在
  
6)回车
用"\r\n",不能用'\r\n'

返回列表