Home  >  Article  >  Backend Development  >  php rtrim(), substr() delete the last character of a string_PHP tutorial

php rtrim(), substr() delete the last character of a string_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:291051browse

There is a saying that we use these two functions to delete the last character of a string. rtrim deletes spaces and some special characters by default, but you can also delete specified characters. For substr, we take the character length. Naturally, as long as Just take the character length and subtract one, as shown in the following example.
*/

$str ='abcea';
echo rtrim($str,'a');


//Method 2

echo '
'.substr($str,0,strlen($str)-1);


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445366.htmlTechArticleWe use these two functions to delete the last character of the string. There is a saying that rtrim deletes spaces by default. and some special characters, but you can also delete specified characters, page substr i...
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