Home > php教程 > php手册 > php中ltrim()、rtrim()与trim()删除字符空格实例,ltrimrtrim

php中ltrim()、rtrim()与trim()删除字符空格实例,ltrimrtrim

WBOY
Release: 2016-06-13 09:20:13
Original
1088 people have browsed it

php中ltrim()、rtrim()与trim()删除字符空格实例,ltrimrtrim

本文实例讲述了php中ltrim()、rtrim()与trim()删除字符空格的方法。分享给大家供大家参考。具体分析如下:

php中的trim函数不能像asp中的一样,可以自动删除所有空格,PHP专业提供了 rtrim() trim()函数,对此感兴趣的朋友可以参考一下。

PHP实例代码如下:

复制代码 代码如下:

$str=" 去除前后空格 ";
echo "方括号中为原始字符串:[".$str."]
";
echo "原始字符串长度:".strlen($str)."
";
$str1=ltrim($str);
echo "执行ltrim()之后的长度:".strlen($str1)."
";
$str2=rtrim($str);
echo "执行rtrim()之后的长度:".strlen($str2)."
";
$str3=trim($str);
echo "执行trim()之后的长度:".strlen($str3)."
";
echo "去掉首尾空格之后的字符串:[".$str3."]";
?>

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template