PHP chop() Function
Example
Remove characters from the right side of a string:
"; echo chop($str,"World!"); ?>Run Example »
Definition and Usage
The chop() function removes whitespace or other predefined characters from the right side of a string.
Syntax
chop(
string,charlist
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to check. |
| charlist | Optional. Specifies which characters to remove from the string. |
如果 charlist 参数为空,则移除下列字符:
Technical Details
| Return Value: | Returns the modified string. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP 4.1.0, the charlist parameter was added. |
More examples
Example 1
Remove the newline character (\n) from the right side of a string:
The HTML output of the above code is as follows (view source):
Hello World!
Hello World!
The browser output of the above code is as follows:
Hello World! Hello World!
Run Example »
PHP String Reference Manual