從 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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP