本文介绍了使用PHP捕获ECHO字符串中的每个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果这看起来真的很基础,我不是PHP开发人员。Aps if this seems really basic, I'm not a PHP developer.好的,这向您展示了如何将字符串中的每个单词都大写OK this shows you how to captalize each word in a stringCapitalise every word of a string in PHP?但是,如何将其结合到PHP中呢?BUT, how do you incorporate this into multiple strings being echoed?例如我有<?php echo $prefillTitle, ' ', $prefillFirstname, ' ', $prefillLastname; ?>我如何使用ucwords()确保每个参数的首字母都作为大写字母回显。会这样简单吗?How would I ensure each parameter echoes with it's first letter as a capital using the ucwords(). Would it be as simple as this?<?php echo ucwords($prefillTitle, ' ', $prefillFirstname, ' ', $prefillLastname; ?>推荐答案 首字母大写每个单词 ucwords 接受一个参数并将每个单词的 first 大写:Capitalizing the first letter of every worducwords takes one argument and capitalizes the first letter of each word:echo ucwords($string); ucwords参考请注意,它将不要将字母的 rest 的大小写设置为小写,因此,如果要确定它们的大小写,可以先使用 strtolower 作为在注释中建议:Note that it will not set the case of the rest of the letters to lowercase, so if you want to be sure that they are, you can use strtolower first as suggested in the comments:echo ucwords(strtolower($string)); strtolower参考如果您想大写字符串(事后看来,我想您是这样做的!),如何使用 strtoupper :If you want to CAPITALIZE THE STRING (which in hindsight I guess you do!), how about using strtoupper:echo strtoupper($string); strtoupper参考有多种连接字符串的方法。您可以使用。运算符:There are multiple ways to concatenate your string. You can use the . operator:$string = $prefillTitle . ' ' . $prefillFirstname . ' ' . $prefillLastname;或者,就像我在上面所做的那样,您可以插值变量:Or, as I have done above, you can interpolate the variables:$string = "$prefillTitle $prefillFirstname $prefillLastname"; 这篇关于使用PHP捕获ECHO字符串中的每个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 07:52