Pick up first letter of each word

1

I am using the following code to capture the first letter of each word. How can I add another rule in preg_split to ignore words such as:

$nome = preg_split("/[\s,_-]+/", $loja->nome);
$iniciais = "";
foreach($nome as $n)
   $iniciais .= $n[0];

echo $iniciais;
    
asked by anonymous 06.12.2017 / 18:24

1 answer

1
<?php

$nome = preg_split("/((de|da|do|dos|das)?)[\s,_-]+/", "A C Loja do Supermercado");
$iniciais = "";
foreach($nome as $n)
{
    if (strlen($n) > 0)
    {
       $iniciais .= $n[0];
    }
}

echo $iniciais;

Check example ONLINE Ideone

preg_split

    
06.12.2017 / 18:36