Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to get first letter of each word in a string with PHP

2 Answers

0 votes
$str = "PHP C Python Java Go Rust C#";
 
$words = explode(" ", $str);
 
foreach($words as $word) {
    echo $word[0] . " ";
}
 
 
 
/*
run:
 
P C P J G R C 
 
*/

 





answered Nov 10, 2022 by avibootz
edited Jun 6, 2023 by avibootz
0 votes
$str = "PHP C Python Java Go Rust C#";
  
preg_match_all('/\b\w/', $str, $matches);

$firstLetters = implode(' ', $matches[0]);

echo $firstLetters; 
  
  
  
  
/*
run:
  
P C P J G R C
  
*/

 





answered Dec 10, 2023 by avibootz
...