• 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 atan2 function – Arc tangent of two variables
  2. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  3. PHP function str_ireplace() – Case-insensitive version of str_replace()
  4. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters
  5. PHP base_convert function – Convert a number between arbitrary bases
  6. PHP function chr() – Generate a single-byte string from a number
  7. PHP bindec function – Convert a number between arbitrary bases
  8. PHP cos function – Cosine
  9. PHP function abs – Absolute value
  10. PHP function acos – Arc cosine

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright