Answers for "get string first character - php"

PHP
28

php get first 5 characters of string

$result = substr("Hello How are you", 0, 5); //first 5 chars "Hello"
Posted by: Guest on February-12-2020
0

php get first character of each word

if(!function_exists('get_avatar')){
    function get_avatar($str){
        $acronym;
        $word;
        $words = preg_split("/(\s|\-|\.)/", $str);
        foreach($words as $w) {
            $acronym .= substr($w,0,1);
        }
        $word = $word . $acronym ;
        return $word;
    }
}
Posted by: Guest on August-30-2021

Code answers related to "get string first character - php"

Browse Popular Code Answers by Language