PHP String trim()函數
PHP字符串修剪()函數是內置函數。愛掏網 - it200.com它用于刪除字符串開頭和結尾的空格,或刪除字符串兩側的空格。愛掏網 - it200.com
trim(string,charlist);
Parameter | Description | Required/Optional |
---|---|---|
String | 指定要檢查的字符串。愛掏網 - it200.com | 必需 |
charlist | 指定要移除的字符。愛掏網 - it200.com 以下字符: | 可選 |
- “
\0
” – 空字符 - “
\t
” – 制表符 - “
\n
” – 換行符 - “
\x0B
” – 垂直制表符 - “
\r
” – 回車符 - “
” – 普通空格
示例1
<?php
str = "Hello PHP!";
echo "Your string is: ".str ."<br>";
echo "By using trim() function :".trim($str,"Hed!");
?>
輸出:
Your string is: Hello PHP!
By using trim() function :llo PHP
示例2
<?php
str = " Hello Javatpoint! ";
echo "Without trim() function: ".str;
echo "<br>";
echo "With trim() function: ".trim($str);
?>
輸出:
Without trim() function: Hello Javatpoint!
With trim() function: Hello Javatpoint!
示例3
<?php
str = "\n\n\nHello Javatpoint\n\n\n";
echo "Without trim() function: " .str;
echo "<br>";
echo "With trim() function:" . trim($str);
?>
輸出:
Without trim() function: Hello Javatpoint
With trim() function:Hello Javatpoint
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。