本代码可以根据用户输入的英文姓名,分析出姓名的首字母输出,比如”Billy Bob” to “B.B.”
<?php function initials($name){ $nword = explode(" ",$name); foreach($nword as $letter){ $new_name .= $letter{0}.'.'; } return strtoupper($new_name); } echo initials('John Doe'); ?>
本代码可以根据用户输入的英文姓名,分析出姓名的首字母输出,比如”Billy Bob” to “B.B.”
<?php function initials($name){ $nword = explode(" ",$name); foreach($nword as $letter){ $new_name .= $letter{0}.'.'; } return strtoupper($new_name); } echo initials('John Doe'); ?>