- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove extra whitespace from the beginning PHP?
If you want to remove extra whitespace from the beginning, use ltrim() in PHP. Let’s say the following is our variable −
$value=" Hello, welcome to PHP Tutorial ";
We want the output with no whitespace on the left −
Hello, welcome to PHP Tutorial
Example
<!DOCTYPE html> <html> <body> <?php $value=" Hello, welcome to PHP Tutorial "; print_r( "The actual value is=".$value."<br>"); echo "The actual length is=",strlen($value)."<br>"; $modifiedValue=ltrim($value); echo "After removing extra whitespace from beginning=",strlen($modifiedValue)."<br>"; echo "The result is=".$modifiedValue; ?> </body> </html>
Output
This will produce the following output
The actual value is= Hello, welcome to PHP Tutorial The actual length is=34 After removing extra whitespace from beginning=32 The result is=Hello, welcome to PHP Tutorial
Advertisements