• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function chop() – Alias of rtrim()

by admin

The chop() function is the pseudonym of rtrim(). This function was introduced in PHP3. 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.

Syntax:

string chop(string string)

Return Values

String stripped of trailing whitespace

Examples

Example 1: Remove trailing whitespace with chop().

<?php 
$string = "\t\tI am a Geek\t\t"; 
echo "Original string: '$string'\n", 
     "chop()'d string: '", chop ($string), "'"; 
?>

Output:

Original string: '        I am a Geek       ' 
chop()'d string: '        I am a Geek'

Example 2:

<?php
$text = “\t\t We are using chop :) ... “; $choped = chop($text);
echo $choped.”
”; $choped = chop($text,” \t.”); echo $choped.”
”; ?>

The output of the above program is as follows:

We are using chop :) ... We are using chop :)
Note: chop() is different than the Perl chop() function, which removes the last character in the string.

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  2. PHP function strcasecmp() – Binary safe case-insensitive string comparison
  3. PHP connection_status function – Returns connection status bitfield
  4. PHP function chr() – Generate a single-byte string from a number
  5. PHP function acos – Arc cosine
  6. PHP base_convert function – Convert a number between arbitrary bases
  7. PHP bindec function – Convert a number between arbitrary bases
  8. PHP atanh function – Inverse hyperbolic tangent
  9. PHP function strlen() – Get string length
  10. PHP function str_repeat() – Repeat a string

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright