回答
有两个部分此。首先,你需要知道如何获得部分字符串。为此,您需要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. C源代码将字符串中的第一个字母从小写字母改为大写字母
- 5. 如何反转字符串中每个字母的大小写?
- 6. 大写字母只能在字符串中最后4个字符
- 7. 小写的字符串,句首字母大写
- 8. 使用jQuery将字符串中的最后一个字母(包含字母和数字)大写使用jQuery
- 9. 如何反转字符串并将最后一个字母设置为小写
- 10. 最小的特殊字符,大写字母和数字
- 11. 使用字符串方法在Java中使用最后一个字母大写
- 12. 检查字符串中的小写字母和大写字母相邻吗?
- 13. 只识别带有大写字母和小写字母的字符串
- 14. 将包含大写字母的字符串转换为小写字母
- 15. 使用中间字符串的VBA代码小写字母到大写字母
- 16. 字符串的首字母大写
- 17. 第一个字母大写小写
- 18. 字符串的最后一个字符应该是一个字母或数字
- 19. 由另一个字符串排序字符串,大写字母第一个
- 20. XSLT - 添加空间小写字母后面的大写字母
- 21. java中两个字符串的大写字母的常见字符/字母
- 22. Android:将字符串的第一个字母转换为小写
- 23. 检查字符串的第一个字母是否大写
- 24. 如何制作字符串大写的第一个字母?
- 25. 如何将字符串中的第一个字母大写?
- 26. 字体小写字母,只是较小的大写字母
- 27. x86汇编:更改一个大写字母为小写字母
- 28. 将最后一个字符串剪成一个字母后用点字符preg_replace
- 29. 计算大写字母,小写字母和其他字符
- 30. 大写字母中的三个字母单词的第一个和最后一个字母
一个字符串?你的意思是一段/句子/单词?否则,你只是在你控制的字符串变量的最后一个位置上执行'strtoupper()'。 –
'echo strrev(ucfirst(strrev(“hello”)))''p – karim79
@ karim79,这比我的想法好得多,你应该把它作为答案。 – Brad