How to use chop in PHP

In this article, I will explain how the chop() function can be used in PHP.
  • 1627

chop() function in PHP

  • The chop() function will remove predefined character from the right end of a string or a white space.

  • The chop() function is an alias of the rtrim() function.

Syntax

chop(string,charlist)

Parameter

  • string string is required parameter. string is determine check to string.
  • charlist charlist is optional parameter. it is determine which character to remove from string.
    if the charlist parameter is empty. The following characters are allowed and is set to be removed :
    • "\0" - ASCII 0, NULL
    • "\t" - ASCII 9, a tab
    • "\n" - ASCII 10, a new line
    • "\x0B" - ASCII 11, a vertical tab.
    • "\r" - ASCII 13, a carriage return
    • " " - ASCII 32, an ordinary white space

Example

The following example show to how the chop() function can be used in PHP.

<html>

<body>

<h3 style="color: violet;">chop() function example in PHP</h3>

   <?php

    $t1="C-sharpcorner ";

    $t2="C-sharpcorner \t\t";

    $t3="\t\tC-sharpcorner \x0A";

    $t4="Dotnet heaven";

    $trimmed_text=chop($t1);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=chop($t2);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=chop($t3);

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=chop($t1,'C');

    var_dump($trimmed_text);

    echo '<br>';

    $trimmed_text=chop($t4,"heaven");

    var_dump($trimmed_text);

    ?> 

</body>

</html>

 

Output

chopphp.jpg
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.