Home >Backend Development >PHP Tutorial >php ltrim() rtrim() trim() removes character spaces_PHP tutorial

php ltrim() rtrim() trim() removes character spaces_PHP tutorial

PHP中文网
PHP中文网Original
2016-07-20 11:03:08910browse

The trim function in php cannot automatically delete all spaces like the one in asp. It professionally provides the rtrim() trim() function. You can refer to it if you need it.

<?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."]";
?>


Statement:
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