You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
//去除字符串首尾的空白字符(或者其他字符)
$str=' hello world '; var_dump(trim($str));
echo '<br>';
//获取字符串长度
$str='hello world'; echo $str.' len:'.strlen($str).'<br>';
//获取中文字符串的长度
$str='你好世界'; $len=mb_strlen($str); echo $str.' len:'.$len.'<br>';
//自动转义字符串,常用于数据库
$sql="select * from talbe1 where 'name'='邝伟键'"; $str=addslashes($sql); echo $str.'<br>'; // select * from talbe1 where \'name\'=\'邝伟键\'
//还原转义字符
$str=stripslashes($str); echo $str.'<br>'; // select * from talbe1 where 'name'='邝伟键'
//分割字符串并转为数组
$str='hello,world,php'; $arr=explode(',',$str); echo '<pre>'; print_r($arr); echo '<br>';
?>
|