回答
有兩個部分此。首先,你需要知道如何獲得部分字符串。爲此,您需要substr()
功能。
接下來,有一個函數用於大寫一個名爲strtotupper()
的字符串。
$thestring="Testing testing 3 2 1. aaaa";
echo substr($thestring, 0, strlen($thestring)-2) . strtoupper(substr($thestring, -1));
令人費解而有趣:
echo strrev(ucfirst(strrev("hello")));
的功能:
function uclast($str) {
return strrev(ucfirst(strrev($str)));
}
這很好!當我這樣輸入時,但是我想要做的是在wordpress中將頁面標題更改爲全部小寫字母和最後一個字母大寫。例如:現在標題顯示爲Sample Page。我希望它顯示爲示例pagE。繼承人我試過,但它不工作的代碼<?php \t \t \t \t \t $ str = the_title(); \t \t \t \t \t echo strrev(ucfirst(strrev($ str))); \t \t \t \t \t?> – Kathy
對不起,不知道如何在這裏做代碼塊:) – Kathy
@Kathy:'$ str = strtolower(the_title());'然後。如果它不起作用,你的'the_title()'函數可能會出錯。 –
這裏有一個算法:
1. Split the string s = xyz where x is the part of
the string before the last letter, y is the last
letter, and z is the part of the string that comes
after the last letter.
2. Compute y = Y, where Y is the upper-case equivalent
of y.
3. Emit S = xYz
當$s
是您的字符串(Demo):
$s[$l=strlen($s)-1] = strtoupper($s[$l]);
或函數中的形式:
function uclast($s)
{
$l=strlen($s)-1;
$s[$l] = strtoupper($s[$l]);
return $s;
}
併爲您的擴展需要擁有的一切小寫,除了最後一個字符明確上 - 大小寫:
function uclast($s)
{
$l=strlen($s)-1;
$s = strtolower($s);
$s[$l] = strtoupper($s[$l]);
return $s;
}
小寫字母/大寫字母/混合字符的情況下的所有內容可用於
<?php
$word = "HELLO";
//or
$word = "hello";
//or
$word = "HeLLo";
$word = strrev(ucfirst(strrev(strtolower($word))));
echo $word;
?>
輸出的所有單詞
hellO
- 1. 返回三個字符串的最後一個字母大寫
- 2. Python:在最後一個小寫字母處拆分字符串
- 3. 帶大寫字母和小寫字母的字符串轉換
- 4. 大寫字母的字符串的第一個字母只
- 5. 在每個大寫字母后加小寫字母后加小寫字母
- 6. 字符串 - 大寫元音,下一個字母的字母 - Javascript
- 7. 將字符串中每個單詞的最後一個字母大寫
- 8. 字符串小寫字母的第一個字符 - C#
- 9. 首字母大寫的字符串首字母大寫
- 10. 大寫只是字符串中的最後一個字母-MS Access
- 11. C源代碼將字符串中的第一個字母從小寫字母改爲大寫字母
- 12. 將字符串中的第一個字符大寫首字母大寫
- 13. 如何反轉字符串中每個字母的大小寫?
- 14. 大寫字母只能在字符串中最後4個字符
- 15. 將小寫字母替換成小寫字母和大寫字母加大寫字母替換字符串的後綴
- 16. 更改字符串從小寫字母到原始大小寫
- 17. 小寫的字符串,句首字母大寫
- 18. 使用jQuery將字符串中的最後一個字母(包含字母和數字)大寫使用jQuery
- 19. 如何反轉字符串並將最後一個字母設置爲小寫
- 20. 最小的特殊字符,大寫字母和數字
- 21. 使用字符串方法在Java中使用最後一個字母大寫
- 22. 使用中間字符串的VBA代碼小寫字母到大寫字母
- 23. C長度不等的字符串,小寫字母到大寫字母
- 24. 檢查字符串中的小寫字母和大寫字母相鄰嗎?
- 25. haskell:將小寫字母更改爲字符串列表中的大寫字母
- 26. 只識別帶有大寫字母和小寫字母的字符串
- 27. Python:替換字符串中的大寫字母和小寫字母
- 28. 將包含大寫字母的字符串轉換爲小寫字母
- 29. 字符串的首字母大寫
- 30. Mysql - 字符串中的大寫字母
一個字符串?你的意思是一段/句子/單詞?否則,你只是在你控制的字符串變量的最後一個位置上執行'strtoupper()'。 –
'echo strrev(ucfirst(strrev(「hello」)))''p – karim79
@ karim79,這比我的想法好得多,你應該把它作爲答案。 – Brad