本文目錄一覽:
php中反轉字符串方法?
strrev
(PHP 4, PHP 5, PHP 7)
strrev — 反轉字符串
說明
strrev ( string $string ) : string
返回 string 反轉後的字符串。
參數
string
待反轉的原始字符串。
返回值
返回反轉後的字符串。
範例
Example #1 使用 strrev() 反轉字符串
add a note add a note
User Contributed Notes 4 notes
6 info at ensostudio dot ru ¶3 months ago
It’s faster and flexible than tianyiw function (comment #122953)
php 字符串倒敘 單詞正序
先要劃分單詞,可以使用preg_split使用\b分段,然後倒序組裝我使用的foreach,程序如下:
?php
function rev($s){
$s2=”;
foreach (preg_split(‘/\b/’,$s) as $a) $s2=$a.$s2;
return $s2;
}
echo rev(‘ I am a boy@, how are you?!’);
?
php中字符串如何反轉輸出
?php
$str=”abcd”;
$len=strlen($str);
$i = $len;
while ($i 0) {
$i=$i-1;
echo substr($str, $i, 1);
}
?
這樣可以不?還是要寫成fuction的形式?
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/271957.html