Home > Article > Backend Development > Detailed example of how to get the initials of an English name in php
This article mainly introduces the method of obtaining the initials of English names in php, involving the explode and strtoupper function operations in phpphp string segmentation and size The related skills of writing conversion have certain reference value. Friends in need can refer to
. This article describes the method of obtaining the initials of English names in PHP. Share it with everyone for your reference. The details are as follows:
This code can analyze and output the first letters of the name based on the English name entered by the user, such as "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'); ?>
The above is the detailed content of Detailed example of how to get the initials of an English name in php. For more information, please follow other related articles on the PHP Chinese website!