PHP rtrim() ਫੰਕਸ਼ਨ
ਇੱਕ ਉਦਾਹਰਣ
ਮੂਲ ਵਾਕ ਦੇ ਸਾਹਮਣੇ ਦੇ ਅੱਖਰਾਂ ਨੂੰ ਹਟਾਓ:
<?php $str = "Hello World!"; echo $str . "<br>"; echo rtrim($str,"World!"); ?>
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
rtrim() ਫੰਕਸ਼ਨ ਮੂਲ ਵਾਕ ਦੇ ਸਾਹਮਣੇ ਦੇ ਖਾਲੀ ਅੱਖਰਾਂ ਜਾਂ ਪ੍ਰਤੀਕਾਂ ਨੂੰ ਹਟਾਉਂਦਾ ਹੈ。
ਸਬੰਧਤ ਫੰਕਸ਼ਨਾਂ:
ਗਿਆਨ ਕਰੋ
rtrim(string,charlist)
Parameter | Description |
---|---|
string | Required. Specify the string to be checked. |
charlist |
Optional. Specify which characters to remove from the string. If omitted, the following characters are removed:
|
Technical Details
Return Value: | Return the modified string. |
PHP Version: | 4+ |
Update Log: | Added in PHP 4.1 charlist Parameter. |
More Examples
Example 1
Remove spaces at the end of the string:
<?php $str = "Hello World! "; echo "Without using rtrim: " . $str; echo "<br>"; echo "Use rtrim: " . rtrim($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> Without using rtrim: Hello World! <br>Using rtrim: Hello World! </body> </html>
Browser output of the above code:
Without using rtrim: Hello World! Use rtrim: Hello World!
Example 2
Remove newline characters (\n) from the right of the string:
<?php $str = "Hello World!\n\n\n"; echo "Without using rtrim: " . $str; echo "<br>"; echo "Use rtrim: " . rtrim($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> Without using rtrim: Hello World! <br>Use rtrim: Hello World! </body> </html>
Browser output of the above code:
Without using rtrim: Hello World! Use rtrim: Hello World!