Home » PHP

PHP chop() Function with Example

PHP chop() Function: Here, we are going to learn about the chop() function with example in PHP.
Submitted by IncludeHelp, on February 07, 2019

PHP chop() Function

chop() function is a string function in PHP, it is used to remove the whitespaces or/and specified character/string from the end of the string.

Syntax:

    chop(string, [char/string]) : string

Here,

  • string is the main string.
  • char/string is an optional parameter, if specifies the single character or set of characters to be removed from the end of the string. If we do not specify the char/string it removes the spaces.

Examples:

    Input:
    str = "IncludeHelp.com#"
    char/string to remove "#"
    Output:
    "IncludeHelp.com"
    Input:
    str = "IncludeHelp.com#"
    char/string to remove "com#"
    Output:
    "IncludeHelp."

    Input:
    str = "IncludeHelp.com#"
    char/string to remove ".com#"
    Output:
    "IncludeHelp"

PHP code:

<?php
	$str = "IncludeHelp.com#";
	
	//removing "#"
	echo (chop($str, "#")."\n");
	//removing "com#"
	echo (chop($str, "com#")."\n");
	//removing ".com#"
	echo (chop($str, ".com#")."\n");
?>

Output

IncludeHelp.com
IncludeHelp.
IncludeHelp






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.