chop

string chop(string string) 

Strips trailing whitespace from a string.

Returns:

String stripped of trailing whitespace

Description:

chop() removes all trailing whitespace characters from the given string. These characters include the horizontal tab (\t), linefeed (\n), vertical tab (\013), carriage return (\r), and space (' '') characters.

Note:

Perl coders may be misled by this function’s name. Perl’s chop() function removes the last character from a string, while PHP’s chop() behaves more like Perl’s chomp(). To simulate the behavior of Perl’s chop(), see the examples.

Version:

PHP 3+, PHP 4+

See also:

To strip whitespace from the start and/or end of a string:

ltrim() 
rtrim() 
trim() 

To grab a substring from a string:

substr() 

Examples: ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.