{"id":12346,"date":"2025-07-14T06:50:28","date_gmt":"2025-07-14T06:50:28","guid":{"rendered":"https:\/\/www.ntspl.co.in\/blog\/?p=12346"},"modified":"2025-07-14T06:50:28","modified_gmt":"2025-07-14T06:50:28","slug":"intelligent-parsing-and-formatting-of-names-in-php-applications","status":"publish","type":"post","link":"https:\/\/www.ntspl.co.in\/blog\/intelligent-parsing-and-formatting-of-names-in-php-applications\/","title":{"rendered":"Intelligent Parsing and Formatting of Names in PHP Applications"},"content":{"rendered":"<p>Name of Person is a PHP package inspired by Basecamp&#8217;s\u00a0name_of_person Ruby gem, which gives you intelligent parsing and multiple formatting options.<\/p>\n<p>Handle person names in your PHP applications with elegant formatting options. Transform names between multiple presentation formats. This package provides a clean, type-safe way to parse, store, manipulate, and display person names consistently across your application.<\/p>\n<p>use HosmelQ\\NameOfPerson\\PersonName;<\/p>\n<p>\/\/ Direct instantiation with first and last name.<\/p>\n<p>$name = new PersonName(&#8216;Eric&#8217;, &#8216;Barnes&#8217;);<\/p>\n<p>\/\/ From full name strings.<\/p>\n<p>$parsed = PersonName::fromFull(&#8216;Yannick Lyn Fatt&#8217;);<\/p>\n<p>echo $parsed-&gt;first; \/\/ &#8220;Yannick&#8221;<\/p>\n<p>echo $parsed-&gt;last; \/\/ &#8220;Fatt&#8221;<\/p>\n<p>\/\/ Handles single names.<\/p>\n<p>$single = PersonName::fromFull(&#8216;Harris&#8217;);<\/p>\n<p>echo $single-&gt;first; \/\/ &#8220;Harris&#8221;<\/p>\n<p>echo $single-&gt;last; \/\/ null<\/p>\n<p>This package also has Laravel support for casts that you can use with your models. The cast supports string-based cast config as well as a fluent method, and JSON serialization:<\/p>\n<p>use HosmelQ\\NameOfPerson\\PersonNameCast;<\/p>\n<p>\/\/ Default configuration &#8211; uses first_name and last_name columns<br \/>\nclass User extends Model<br \/>\n{<br \/>\nprotected function casts(): array<br \/>\n{<br \/>\nreturn [<br \/>\n&#8216;name&#8217; =&gt; PersonNameCast::class,<br \/>\n];<br \/>\n}<br \/>\n}<\/p>\n<p>$user-&gt;name = &#8216;Eric L. Barnes&#8217;;<\/p>\n<p>echo $user-&gt;name-&gt;familiar(); \/\/ &#8220;Eric B.&#8221;<br \/>\necho $name-&gt;initials(); \/\/ &#8220;ELB&#8221;<br \/>\necho $name-&gt;possessive(&#8216;first&#8217;); \/\/ Eric&#8217;s<\/p>\n<p>\/\/ Fluent cast<br \/>\nreturn [<br \/>\n&#8216;author_name&#8217; =&gt; PersonNameCast::using(&#8216;author_first&#8217;, &#8216;author_last&#8217;),<br \/>\n];<\/p>\n<p><strong>Main Features<\/strong><br \/>\nMultiple Format Options: nine different ways to display names (full, familiar, abbreviated, initials, sorted, possessive, mentionable)<br \/>\nSmart Parsing: Intelligently handles full name strings and edge cases<br \/>\nUnicode Support: Full international name support with proper multibyte handling<br \/>\nPure PHP: Core functionality works in any PHP project<br \/>\nLaravel Integration: Native Eloquent casting for seamless database integration<\/p>\n<p data-start=\"100\" data-end=\"635\"><a href=\"https:\/\/www.ntspl.co.in\/services\/web-development\/\"><strong>NTSPL<\/strong><\/a> has established itself as a trusted provider of high-quality <a href=\"https:\/\/www.ntspl.co.in\/services\/web-development\/\"><strong>PHP development services<\/strong><\/a>. With a focus on performance, scalability, and clean coding practices, the company consistently delivers solutions that meet the unique needs of its clients. Whether it\u2019s building custom web applications, optimizing existing systems, or integrating powerful features, NTSPL&#8217;s expertise in PHP ensures reliable and effective results. For businesses seeking dependable development partners, NTSPL stands out as a strong choice.<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n<pre><code class=\"torchlight\" data-theme=\"github-light\" data-lang=\"php\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Name of Person is a PHP package inspired by Basecamp&#8217;s\u00a0name_of_person Ruby gem, which gives you intelligent parsing and multiple formatting options. Handle person names in your PHP applications with elegant formatting options. Transform names between multiple presentation formats. This package provides a clean, type-safe way to parse, store, manipulate, and display person names consistently across [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":12410,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-12346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":{"custom_meta_title":"Intelligent Name Parsing & Formatting in PHP | Best Practices & Tools","meta_description":"Learn how to intelligently parse and format names in PHP applications. Discover best practices, real-world examples, and top libraries to improve data accuracy and user experience.","meta_keyword":"","other_meta_tag":""},"_links":{"self":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/12346"}],"collection":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/comments?post=12346"}],"version-history":[{"count":1,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/12346\/revisions"}],"predecessor-version":[{"id":12411,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/12346\/revisions\/12411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media\/12410"}],"wp:attachment":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media?parent=12346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/categories?post=12346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/tags?post=12346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}