$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 plus2netThanksIn 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 ThanksOther 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
$str = "Hello World!!!";
echo chop($str, "!"); // Output: "Hello World"
$str = "abcdefxyz";
echo chop($str, "xyz"); // Output: "abcdef"
$str = "Data123";
echo chop($str, "123"); // Output: "Data"
$str = "Hello!!!???";
echo chop($str, "!?"); // Output: "Hello"
$str = "Hello World";
echo chop($str, "?"); // Output: "Hello World" (No effect as '?' is not present)
Author
🎥 Join me live on YouTubePassionate 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.