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

怪我咯
Release: 2023-03-12 21:24:02
Original
1806 people have browsed it

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;); 
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!