PHP rtrim() ਫੰਕਸ਼ਨ

ਇੱਕ ਉਦਾਹਰਣ

ਮੂਲ ਵਾਕ ਦੇ ਸਾਹਮਣੇ ਦੇ ਅੱਖਰਾਂ ਨੂੰ ਹਟਾਓ:

<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>

Run Instance

ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ

rtrim() ਫੰਕਸ਼ਨ ਮੂਲ ਵਾਕ ਦੇ ਸਾਹਮਣੇ ਦੇ ਖਾਲੀ ਅੱਖਰਾਂ ਜਾਂ ਪ੍ਰਤੀਕਾਂ ਨੂੰ ਹਟਾਉਂਦਾ ਹੈ。

ਸਬੰਧਤ ਫੰਕਸ਼ਨਾਂ:

  • ltrim() - ਮੂਲ ਵਾਕ ਦੇ ਵੱਲੋਂ ਖਾਲੀ ਅੱਖਰਾਂ ਜਾਂ ਪ੍ਰਤੀਕਾਂ ਨੂੰ ਹਟਾਓ
  • trim() - ਮੂਲ ਵਾਕ ਦੇ ਦੋਹਾਂ ਤਰਫ ਦੇ ਖਾਲੀ ਅੱਖਰਾਂ ਜਾਂ ਪ੍ਰਤੀਕਾਂ ਨੂੰ ਹਟਾਓ

ਗਿਆਨ ਕਰੋ

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:

  • "\0" - NULL
  • "\t" - Tab
  • "\n" - Newline
  • "\x0B" - Vertical Tab
  • "\r" - Carriage Return
  • " " - Space

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!

Run Instance

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!

Run Instance