php - Get first character of a string, that is a French accent -


this question has answer here:

i have strange problem , not sure how resolve it. first character of text field database. character, apply css style make big.

if try following code, understand problem:

<?php $str_en = "i sentence."; echo $str_en[0];  echo "<br /><br />";  $str_fr = "À tous les jours je fais du php."; echo $str_fr[0];  echo "<br /><br />";  $str_fr = "Étais-tu ici?"; echo $str_fr[0]; ?> 

the code above output:

i

Ã

Ã

it seems french character using more 1 bytes in string. problem not sentence start french character. have idea how have function convert this:

<?php $str_fr = "Étais-tu ici?"; ?> 

to this

$str_fr = "<span class='firstletter'>É</span>tais-tu ici?"; 

or perhaps there better way css3 this.

see mb_substr (http://www.php.net/manual/en/function.mb-substr.php)

$first_char = mb_substr($string, 0, 1, 'utf-8'); // may change forth parameter according needed encoding. 

mb_substr repects encoding , returns bytes representing first character here.


css3 has pseudo-class ::first-letter selects first letter.

example:

your html is:

<p id="french_text">Étais-tu ici?</p> 

then can address css3 by:

p:first-letter { /* properties */ } 

(p.s.: nowadays' standard using ::first-letter (double double colon instead of single double colon), best backwards compability use 1 double colon)


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -