我正在编写一个程序,我需要在字符串中输入每个单词的大写字母。
喜欢,我的名字是汗成为我的名字是汗我们有一个php函数ucwords for it。
但如何处理这样的情况...
my Name Is Khan
实际输出::
My Name Is Khan
预期输出::(M和'a'的汗应该是红色的)
*this
答案 0 :(得分:0)
试试这个,
$string = 'my Name Is Khan';
$string = ucwords($string);
echo $string = ucwords(strtolower($string));
此代码使每个字母大写的第一个字符
答案 1 :(得分:0)
试试此代码
<?php
$title = "<span style='color:red'>";
$title .= strtoupper("m");
$title .= "</span>y name is kh<span style='color:red'>a</span>n";
echo ucwords($title);
?>
答案 2 :(得分:0)
CSS可用于实现它:
使用文本转换属性创建类
<style>
.ucword{ text-transform:capitalize; }
</style>
<br/><br/>
<?php
$title="<p class='ucword'><span style='color:red'>m</span>y name is kh<span style='color:red'>a</span>n</p>";
echo $title;
?>