U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

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


You can utilize the PHP rtrim() capacity to strip whitespace from the finish of a string.

SOLUTION:


rtrim 

(PHP 4, PHP 5, PHP 7) 

rtrim - Remove spaces (or different characters) from end of string 

Description

rtrim (string $ str [, string $ character_mask]): string 

Returns the string str, in the wake of erasing all the clear characters (or different characters) toward the finish of the string. 


Called without the subsequent parameter, rtrim () will erase the accompanying characters:


We should look this exemple:


Example


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

if you want to improve the solution
comment to help the community
Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage