Q:

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

0

How to remove white space from the beginning 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 ltrim() function

You can use the PHP ltrim() function to strip whitespace from the beginning of a string.

Let's take a look at an example to understand how this function really works:

<?php
$my_str = '    Hello World!';
echo strlen($my_str); // Outputs: 16
 
$trimmed_str = ltrim($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 remove white space from the end of a string... >>
<< How to convert special HTML entities back to chara...