PHP chop() Function with Example

PHP chop() Function with Example

PHP chop() Function: Here, we will find out about the chop() work with the example in PHP.

PHP chop() Function

chop() work is a string capacity in PHP, it is utilized to evacuate the whitespaces or/and determined character/string from the finish of the string.

Syntax:

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

Here,

  • the string is the fundamental string.
  • roast/string is a discretionary parameter if determines the single character or set of characters to be expelled from the finish of the string. On the off chance that we don’t determine the scorch/string, it evacuates the spaces.

Example:

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

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

PHP Code:

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

Output:

JustTechReview.com
JustTechReview.
JustTechReview

Recent Posts

error: Alert: Content is protected!!