當前位置:首頁 » 編程語言 » php反轉字元串函數

php反轉字元串函數

發布時間: 2025-04-23 18:49:19

❶ 在php中如何把abcdefg輸出後為gfedcba

就是逆序字元串,比如原字元串為「abcdefg」,逆轉後的字元串就是「gfedcba」

❷ 在php下,如何讓每個字母的末尾變成大寫字母求代碼過程!

1.字元串反轉

<?php
$str="Hello world";
$result=strrev($str);
echo $result;
//輸出的結果是:dlrow olleH;
?>
2.首字母大寫<?php
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
3.字元串反轉回來
<?php
$str="Hello world";
$result=strrev($str);
echo $result;
//輸出的結果是:dlrow olleH;
?>

❸ PHP中addslashes()和stripslashes()實現字元串轉義和還原用法實例

本文實例講述了PHP中addslashes()和stripslashes()實現字元串轉義和還原用法。分享給大家供大家參考,具體如下:
PHP中addslashes()
函數返回在預定義字元之前添加反斜杠的字元串。
預定義字元是:
單引號(')
雙引號(")
反斜杠(\)
NULL
stripslashes()
函數刪除由
addslashes()
函數添加的反斜杠。
用法示例如下:
<?php
$str="select
*
from
`book`
where
bookname='腳本之家'";
echo
$str."<br/>";//輸出字元串$str
echo
$astr=addslashes($str);//字元串轉義並輸出空行數
echo
"<br/>";
echo
stripslashes($astr);//將轉義字元串還原
?>
運行結果如下:
select
*
from
`book`
where
bookname='腳本之家'
select
*
from
`book`
where
bookname=\'腳本之家\'
select
*
from
`book`
where
bookname='腳本之家'
補充:
addslashes()與addcslashes()函數的區別:
這是兩個寫法非常相近但是使用有所區別的函數,addslashes()
函數返回在預定義字元之前添加反斜杠的字元串,而addcslashes()
函數返回在指定字元前添加反斜杠的字元串,因此addcslashes()
函數需要添加附加參數說明需要添加反斜杠的具體字元。
二者具體區別與帶蔽用法可參考本站相關文章《解析php
addslashes()與addcslashes()函數的區別和比較》
希望本文所述對大家PHP程序設計有所幫助。斗首

熱點內容
怎麼配置serial窗口 發布:2025-04-25 23:32:24 瀏覽:961
java配置路徑 發布:2025-04-25 23:29:44 瀏覽:824
閃迪存儲卡g 發布:2025-04-25 23:24:51 瀏覽:211
c語言和It 發布:2025-04-25 23:18:22 瀏覽:694
c語言簡單程序設計 發布:2025-04-25 23:13:14 瀏覽:593
c語言編程思路 發布:2025-04-25 23:08:08 瀏覽:341
安卓開發存儲空間多少則為不足 發布:2025-04-25 22:54:55 瀏覽:541
視頻課堂源碼 發布:2025-04-25 22:52:55 瀏覽:982
庭院植物配置需要什麼 發布:2025-04-25 22:46:47 瀏覽:985
存儲卡ntfs 發布:2025-04-25 22:42:57 瀏覽:76