WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

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

Topic: PHP / MySQLPrev|Next

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

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties