PHP Delete string trailing white space character function chop ()

Source: Internet
Author: User
Tags chop rtrim

Definition and usage

The chop () function removes white space characters or other predefined characters to the right of the string.

Grammar

Chop (string,charlist)

Chop performs the removal of whitespace processing, get_html_translation_table returns the conversion list to the variable, and defines the string that includes the HTML encoding Htmlentities,htmlspecialchars_decode Defines a string that contains HTML special characters, NL2BR Quotemeta RTrim, and so on.

Definition and Usage: the chop () function removes whitespace characters or other predefined characters from the end of the string, and aliases the function's RTrim () function.

Syntax: Chop (string,charlist), the code is as follows:

Copy the code code as follows:

$str = "I ' m a   teacher  ";          Defines the string $result =chop ($STR);           Perform the removal of whitespace to handle echo $result;            Output results

Parameter description

string is required. Specifies the string to check.

Charlist is optional. Specifies which characters are removed from the string.
If the charlist parameter is empty, the following characters are removed:

"\"-NULL "\ T"-tab "\ n"-newline "\x0b"-vertical tab "\ r"-Carriage return ""-space

Technical details return value:

Returns the modified string.

Example 1

Remove the line break (\ n) to the right of the string:

<?php$str = "Hello world!\n\n"; echo $str; Echo Chop ($STR);? >

The HTML output of the above code is as follows (see source code):

<! DOCTYPE Html>

The browser output of the above code is as follows:

Hello world! Hello world!

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.