溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PHP刪除字符串最后一個字符的方法

發(fā)布時間:2020-06-09 11:23:57 來源:億速云 閱讀:229 作者:Leah 欄目:編程語言

這篇文章主要介紹了PHP刪除字符串最后一個字符的方法,具有一定借鑒價值,需要的朋友可以參考下。如下資料是刪除字符串最后一個字符方法的詳細步驟。

在PHP中可以使用“rtrim()”函數(shù)去掉最后一個字符,該函數(shù)用于刪除字符串末端的空白字符或者其它字符,其語法是“rtrim(str,char) ”,其參數(shù)str表示要操作的字符串,參數(shù)char表示要去除的字符。

使用范例

<?php
$text = "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = rtrim($text);
var_dump($trimmed);
$trimmed = rtrim($text, " \t.");
var_dump($trimmed);
$trimmed = rtrim($hello, "Hdle");
var_dump($trimmed);
// 刪除 $binary 末端的 ASCII 碼控制字符
// (包括 0 - 31)
$clean = rtrim($binary, "\x00..\x1F");
var_dump($clean);
?>

以上例程會輸出:

string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"
string(30) "        These are a few words :) ..."
string(26) "        These are a few words :)"
string(9) "Hello Wor"
string(15) "    Example string"

以上就是PHP刪除字符串最后一個字符的方法,看完之后是否有所收獲呢?如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI