實現英文註冊用戶首字母大寫

一 代碼

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  3. <htmlxmlns="http://www.w3.org/1999/xhtml">

  4. <head>

  5. <metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>

  6. <title>統一英文註冊用戶首字母大寫</title>

  7. </head>

  8. <body>下載 

  9. <formname="form"method="post"action="#">

  10. <label>用戶名:</label>

  11. <input type="text" name="name" id="name" value="<?php echo $_POST['name'];?>"><br>

  12. <inputtype="submit"name="sub"value="提交"><p>

  13. </form>

  14. <?php

  15. if(!empty($_POST['name'])){//判斷文本框的值是否爲空

  16.   $temp=ucfirst($_POST['name']);//把傳過來的英文名的首字母變成大寫

  17. }

  18. echo "首字母統一爲大寫:".$temp;//輸出首字母統一爲大寫的用戶名

  19. ?>

  20. </body>

  21. </html>

二 運行效果


 

三 說明

string ucfirst下載 ( string $str )

將 str 的首字符(如果首字符是字母)轉換爲大寫字母,並返回這個字符串。 

參數 

str

輸入字符串。 

返回值 

返回結果字符串。 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章