PHP输出中每个单词的第一个大写字母
我希望输出的每个单词的第一个字母都是大写的。这是我的密码PHP输出中每个单词的第一个大写字母,php,capitalization,Php,Capitalization,我希望输出的每个单词的第一个字母都是大写的。这是我的密码 function random_title () { $quotes1 = file ("wp-content/plugins/includes/classes/quotes.txt", FILE_IGNORE_NEW_LINES); $quotes1 = ucwords($quotes1); $num = rand (0, intval (count ($quotes1) / 3)) * 3; ret
function random_title ()
{
$quotes1 = file ("wp-content/plugins/includes/classes/quotes.txt", FILE_IGNORE_NEW_LINES);
$quotes1 = ucwords($quotes1);
$num = rand (0, intval (count ($quotes1) / 3)) * 3;
return $quotes1[$num];
}
用途是:
random_title()
这部分不起作用,我做错了什么?当我把它放进去时,我没有得到任何输出,但是如果我把它拿出来,我会得到我的标题,但是它们是小写的,就像它们在文本文件中一样
$quotes1 = ucwords($quotes1);
谢谢您的帮助。只处理单个字符串,而不是数组。只需在选择随机标题后应用它即可:
function random_title ()
{
$quotes1 = file ("wp-content/plugins/includes/classes/quotes.txt", FILE_IGNORE_NEW_LINES);
$num = rand (0, intval (count ($quotes1) / 3)) * 3;
return ucwords($quotes1[$num]); # Here!
}
您需要使用ucfirst以大写字母书写第一个字母。您需要在返回时使用它,我认为基于
return$quotes1[$num]
,$quotes1
是一个数组,但ucwords()
用于字符串-。您可以执行返回ucwords($quotes1[$num])代码>这是完美的。它成功了。非常感谢。但是应该把所有的信都封起来吗?是吗?@anantkumarsinghucwords
将每个单词的第一个字符大写。还是我误解了你的评论?是的,上面的代码输出为:这是你的输出