Please note, this is a STATIC archive of website www.tutorialrepublic.com from 10 Sep 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
Advertisements

How to remove white space from the end of a string in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the PHP rtrim() function

You can use the PHP rtrim() function to strip whitespace from the end of a string.

Let's check out an example to understand how this function basically works:

<?php
$my_str = 'Hello World!    ';
echo strlen($my_str); // Outputs: 16
 
$trimmed_str = rtrim($my_str);
echo strlen($trimmed_str); // Outputs: 12
?>

Related FAQ

Here are some more FAQ related to this topic:

Advertisements
Bootstrap UI Design Templates