The PHP character filtering function removes the last comma (rtrim) of the string)

Source: Internet
Author: User
Tags control characters
The PHP character filter function removes the last comma of the string. it is easier to use the built-in functions of php to solve the problem,

Trim filters both ends of a string,
Rtrim filters the tail of the string, = chop ()
Ltrim filters the string header.

You can only use str_replace to filter the Middle Keys in a string.
For example,

PHP code

The code is as follows:


$ Str = '1970 ,';
Echo rtrim ($ str ,',');

Rtrim instance code 2

The code is as follows:


$ Text = "\ t \ tThese are a few words :)...";
$ Trimmed = rtrim ($ text );
// $ Trimmed = "\ t \ tThese are a few words :)..."
$ Trimmed = rtrim ($ text, "\ t .");
// $ Trimmed = "\ t \ tThese are a few words :)"
$ Clean = rtrim ($ binary, "\ x00.. \ x1F ");
// Trim the ASCII control characters at the end of $ binary
// (From 0 to 31 random sive)
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.