Home  >  Article  >  Backend Development  >  Detailed example of how to get the initials of an English name in php

Detailed example of how to get the initials of an English name in php

怪我咯
怪我咯Original
2017-07-06 10:44:551849browse

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}.&#39;.&#39;; 
  } 
  return strtoupper($new_name); 
} 
echo initials(&#39;John Doe&#39;); 
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn