How to remove white space from the end of a string in PHP
rtrim()
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 ?>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the PHP
rtrim()functionYou 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:
need an explanation for this answer? contact us directly to get an explanation for this answer