Javascript 我想将这个echo块中php字符串的值大写

Javascript 我想将这个echo块中php字符串的值大写,javascript,php,html,Javascript,Php,Html,这是我的php代码块,我想将字符串从$user->data['username\u clean']返回的值中的第一个字母大写 我尝试的方法无法处理此错误 致命错误:调用未定义的方法 然而,很可能是我格式化不正确。php代码在这里 <?php if ($user->data['user_id'] == ANONYMOUS) { echo ' <li class="dropdown"> <a href="#" class="

这是我的php代码块,我想将字符串从
$user->data['username\u clean']
返回的值中的第一个字母大写

我尝试的方法无法处理此错误

致命错误:调用未定义的方法

然而,很可能是我格式化不正确。php代码在这里

<?php 
if ($user->data['user_id'] == ANONYMOUS) {
   echo '
        <li class="dropdown">
           <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Login<span class="caret"></span></a>
           <ul class="dropdown-menu">
              <form id="loginform" method="post" action="/forums/ucp.php?mode=login">
                 <label>Username</label>
                 <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" />
                 <label>Password</label>
                 <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" />
                  <label>Remember Me?:</label>
                  <input type="checkbox" name="autologin">
                  <input type="submit" value="Login" name="login">
                  <input type="hidden" name="redirect" value="indextest.php"
              </form>
        </li>';
} else { 
    echo '
        <li class=dropdown>
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"  aria-haspopup="true" aria-expanded="false">',  $user->data['username_clean'], '<span class="caret"></span></a>
        <ul class="dropdown-menu">
                    <li><a href="#">User Control Panel</a></li>
                    <li><a href="#">Profile</a></li>
                    <li><a href="#">Logout</a></li>
                  </ul>
        </li>';
}
?>

到大写字符串的第一个字符使用

ucfirst( $user->data['username_clean'] );

要大写字符串的第一个字符,请使用

ucfirst( $user->data['username_clean'] );

大写使用
ucfirst
的第一个字符,如下所示:

ucfirst( $user->data['username_clean'] );
ucfirst-使字符串的第一个字符大写

说明

字符串ucfirst(字符串$str)

来源

另外,另一种创造性的解决方案是这样做(尽管你可能不想这样做,但思考起来很有趣):


您正在访问第一个字符
{0}
,并将其更改为大写。

大写使用
ucfirst
的第一个字符,如下所示:

ucfirst( $user->data['username_clean'] );
ucfirst-使字符串的第一个字符大写

说明

字符串ucfirst(字符串$str)

来源

另外,另一种创造性的解决方案是这样做(尽管你可能不想这样做,但思考起来很有趣):

您正在访问第一个字符
{0}
并将其更改为大写。

是将字符串中的第一个字母大写的PHP函数

因此,您需要在该调用中包装您希望资本化的值

尝试更改:

 $user->data['username_clean'], 
致:

是将字符串中的第一个字母大写的PHP函数

因此,您需要在该调用中包装您希望资本化的值

尝试更改:

 $user->data['username_clean'], 
致:


您可以使用将Stings的第一个字母大写,那么这在代码中会是什么样子呢?查看@RiggsFolly的答案确保也接受适当的答案(复选框),您可以使用该复选框将Stings的第一个字母大写,那么这在代码中会是什么样子?查看@RiggsFolly的答案确保也接受适当的答案(复选框)谢谢谢谢谢谢谢谢谢谢谢谢谢谢