How to check if letter is upper or lower in PHP?

后端 未结 13 1189
忘了有多久
忘了有多久 2020-12-04 19:12

I have texts in UTF-8 with diacritic characters also, and would like to check if first letter of this text is upper case or lower case. How to do this?

13条回答
  •  猫巷女王i
    2020-12-04 19:55

    echo preg_match('~^\p{Lu}~u', $string_data) ? 'Upper' : 'lower';
    
    /** Please check below lines. I have elaborate above code. **/
    
    ~      ; start pattern delimiter 
    ^      ; match from the start of the input string
    \p{Lu} ; match exactly one uppercase letter (Unicode safe)
    ~      ; ending pattern delimiter 
    u      ; enable unicode match
    

提交回复
热议问题