從 PHP 開頭移除額外的空格?


如果你想要移除開頭的多餘空格,在 PHP 中使用 ltrim()。我們假設這個變數如下:

$value="  Hello, welcome to PHP Tutorial  ";

我們想要一個左側沒有空格的輸出:

Hello, welcome to PHP Tutorial

示例

 即時演示

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

輸出

這將產生以下輸出

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

更新於:2020 年 10 月 13 日

149 次觀看

啟動你的職業

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.