chop() : remove string from right end

$string='Welcome to plus2net.com';
echo chop($string,'.com');
output
Welcome to plus2net
WE can remove white space at the end of the string .
echo chop("welcome to plus2net  ");
Output
welcome to plus2net
To indentify the removal of white space we will add one more string and check like this.
$str="Welcome to plus2net  ";
//echo $str;
echo chop($str);
echo "Thanks";
The output is here
Welcome to plus2netThanks
In the above code we can check the difference by un-commenting 2nd line and adding the comment to third line. We will see the gap before the word Thanks
Welcome to plus2net Thanks
Other than white space we can also remove these .
"\0"-ASCII 0, null
"\t" Tab
"\r" carriage return
"\n" new line
"\x0B" vertical tab
" " white space

Example: Chopping Specific Characters

$str = "Hello World!!!";
echo chop($str, "!");  // Output: "Hello World"

Example: Chopping Multiple Characters

$str = "abcdefxyz";
echo chop($str, "xyz");  // Output: "abcdef"

Example: Removing Trailing Numbers

$str = "Data123";
echo chop($str, "123");  // Output: "Data"

Example: Removing Multiple Characters from the End

$str = "Hello!!!???";
echo chop($str, "!?");  // Output: "Hello"

Example: No Effect if Character Not Present

$str = "Hello World";
echo chop($str, "?");  // Output: "Hello World" (No effect as '?' is not present)

String Functions chunk_split(): Split a string into smaller chunks
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer