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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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_word_count() – Return information about words used in a string
  2. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters
  3. PHP function str_repeat() – Repeat a string
  4. PHP atanh function – Inverse hyperbolic tangent
  5. PHP function strcasecmp() – Binary safe case-insensitive string comparison
  6. How to test a PHP script
  7. PHP function str_ireplace() – Case-insensitive version of str_replace()
  8. PHP function chunk_split() – Split a string into smaller chunks
  9. PHP function abs – Absolute value
  10. htaccess Cheatsheet

You May Also Like

Primary Sidebar

Recent Posts

  • “aws s3 mv” Command Examples
  • “aws s3 mb” Command Examples
  • “aws s3 ls” Command Examples
  • “aws s3 cp” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright