How to get all first character in sentences using PHP? -


what want first character in sentences, knew substr can this, substr able 1 character.

i use code now, h instead of hw

substr($string,0,1); 

what want is

$string = "hello world"; $result = "hw"; 

any idea how ?

thanks

$string = 'hello, world!'; $result = ''; foreach (preg_split('#[^a-z]+#i', $string, -1, preg_split_no_empty) $word) {     $result .= $word[0]; } var_dump($result); 

demo: https://eval.in/158045


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -