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


 Live Demo

<!DOCTYPE html>
   $value="  Hello, welcome to PHP Tutorial  ";
   print_r( "The actual value is=".$value."<br>");
   echo "The actual length is=",strlen($value)."<br>";
   echo "After removing extra whitespace from beginning=",strlen($modifiedValue)."<br>";
   echo "The result is=".$modifiedValue;


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