U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

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


How to remove white space from the beginning of a string in PHP,ltrim,php problems,string ltrim php

You can use the PHP ltrim () capacity to strip whitespace from the earliest starting point of a string.

SOLUTION :

ltrim
(PHP 4, PHP 5, PHP 7)

ltrim - Remove spaces (or other characters) from start of string

Description:

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

Removes spaces (or other characters) from the beginning of the string.


We should look this exemple:

Example

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

strlen - Calculate the size of a string

Returns the size of the string string.



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

Post a Comment

NameEmailMessage