PHP chop () function
Examples
Remove the right of the character string:
<?php
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"World!");
?>
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"World!");
?>
Running instance »
Definition and Usage
chop () function removes the right of a string of blank characters or other predefined characters.
grammar
chop( string,charlist )
参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
charlist | 可选。规定从字符串中删除哪些字符。 如果 charlist 参数为空,则移除下列字符:
|
technical details
return value: | Returns the modified string. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 4.1.0, add the charlist parameters. |
More examples
Example 1
Remove the string on the right side of the newline (\ n):
<?php
$str = "Hello World!\n\n";
echo $str;
echo chop($str);
?>
$str = "Hello World!\n\n";
echo $str;
echo chop($str);
?>
HTML output of the code above is as follows (view source):
<!DOCTYPE html>
<html>
<body>
Hello World!
Hello World!
</body>
</html>
<html>
<body>
Hello World!
Hello World!
</body>
</html>
Browser output of the code above is as follows:
Hello World! Hello World!
Running instance »
PHP String Reference