In PHP, you can use the PHP built-in function "rtrim()" to remove the characters at the end of the string. The rtrim function can directly remove the blank characters or other predefined characters on the right side of the string and return the modified String, its syntax is [rtrim($str,$last_char)].
rtrim() function removes whitespace characters or other predefined characters on the right side of a string and returns the modified string.
(Recommended tutorial: php video tutorial)
Syntax:
rtrim(string,charlist)
Parameter introduction:
string Required. Specifies the string to check.
#charlist Optional. Specifies which characters are removed from a string.
(Related recommendations: php training)
Code implementation:
$str = '123,234,345,'; echo $str,'<br/>'; //1、使用substr()函数实现去除字符串末尾字符 echo substr($str,0,-1),'<br/>';//123,234,345 //2、使用rtrim()函数实现去除字符串末尾字符 //2.1、已知末尾字符 echo rtrim($str,','),'<br/>';//123,234,345 //2.2、不知道末尾字符,需先获取末字符 $last_char=$str{strlen($str)-1}; // ',' //或者: $last_char=substr($str,-1); // ',' echo rtrim($str,$last_char);//123,234,345
The above is the detailed content of How to remove characters at the end of string in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools
