4

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

 2 years ago
source link: https://www.laravelcode.com/post/how-to-remove-white-space-from-the-end-of-a-string-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

  1500 views

  2 years ago

PHP

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
?>

i hope this small article will help you.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK