php method to delete the first space in a string: first create a PHP sample file; then define a string containing spaces; finally delete the white space characters on the left side of the string through the ltrim function.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to delete the first string in php Space?
In PHP, you can use the ltrim() function to remove blank characters or other predefined characters on the left side of a string.
Syntax
ltrim(string,charlist)
Example
Remove spaces on the left side of the string:
<?php $str = " Hello World!"; echo "不使用 ltrim: " . $str; echo "<br>"; echo "使用 ltrim: " . ltrim($str); ?>
HTML output of the above code (please view the source code):
<!DOCTYPE html> <html> <body> 不使用 ltrim: Hello World!<br>使用 ltrim: Hello World! </body> </html>
Browser output of the above code:
不使用 ltrim: Hello World! 使用 ltrim: Hello World!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to delete the first space in a string in php. For more information, please follow other related articles on the PHP Chinese website!