How to use chop in PHP
In this article, I will explain how the chop() function can be used in PHP.
chop() function in PHP
Syntax
Parameter
- string string is required parameter. string is determine check to string.
-
charlist charlist is optional parameter. it is determine which character to remove from string.
if the charlist parameter is empty. The following characters are allowed and is set to be removed :
- "\0" - ASCII 0, NULL
- "\t" - ASCII 9, a tab
- "\n" - ASCII 10, a new line
- "\x0B" - ASCII 11, a vertical tab.
- "\r" - ASCII 13, a carriage return
- " " - ASCII 32, an ordinary white space
Example
The following example show to how the chop() function can be used in PHP.
<html>
<body>
<h3 style="color: violet;">chop() function example in PHP</h3>
<?php
$t1="C-sharpcorner ";
$t2="C-sharpcorner \t\t";
$t3="\t\tC-sharpcorner \x0A";
$t4="Dotnet heaven";
$trimmed_text=chop($t1);
var_dump($trimmed_text);
echo '<br>';
$trimmed_text=chop($t2);
var_dump($trimmed_text);
echo '<br>';
$trimmed_text=chop($t3);
var_dump($trimmed_text);
echo '<br>';
$trimmed_text=chop($t1,'C');
var_dump($trimmed_text);
echo '<br>';
$trimmed_text=chop($t4,"heaven");
var_dump($trimmed_text);
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here