Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to create a new line in PHP... >>
<< How to remove white space from the beginning of a ...