PHP chop

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : chop() function

Description

The chop() function is used to remove the whitespaces and other predefined characters from the right side of a string. This function is an alias of rtrim() function.

Version

(PHP 4 and above)

Syntax

chop(string_name, char_list)

Parameters

Name

Description

Required /
Optional

Type

string_name

The string that will be trimmed.

Required

String

char_list

Specifies which character to remove from the string. Without this parameter, the function removes the following characters. 
An ordinary space. 
�" - the NULL-byte. 
" - tab. 
" - line feed. 
x0B" - a vertical tab. 
" " - a carriage return.

Optional

String

Return values

The changed string.

Value Type : String.

Pictorial Presentation

php-string-chop()

Example :

  1.  

  2. $text1="w3resource.com  ";  

  3. $text2="w3resource.com ";  

  4. $text3=" w3resource.comx0A";  

  5. $text4="Good Morning";

      

     

  6.  

    $trimmed_text=chop($text1);  

  7. var_dump($trimmed_text);  

  8. echo '
    ';  

  9. $trimmed_text=chop($text2);  

  10. var_dump($trimmed_text);  

  11. echo '
    ';  

  12. $trimmed_text=chop($text3);  

  13. var_dump($trimmed_text);  

  14. echo '
    ';  

  15. $trimmed_text=chop($text1,'w3');  

  16. var_dump($trimmed_text);  

  17. echo '
    ';  

  18. $trimmed_text=chop($text4,"ng");  

  19. var_dump($trimmed_text);  

  20. ?>  

  21.  

      

     

Output :

string(14) "w3resource.com" 
string(14) "w3resource.com" 
string(16) " w3resource.com" 
string(16) "w3resource.com " 
string(10) "Good Morni"