Special character handling like œ, …, ’ ...turning into ? mark in the textarea

Discussion in 'PHP' started by shiva_rnm, Aug 15, 2009.

  1. #1
    Hi All,

    If i enter special char like œ, …, ’ ...turning into ? mark in the textarea as well as in the DB. I used $str = str_replace("œ","œ",$str); ...but its not at detecting œ special char....it just turns into ? mark .

    what action i've to take before entering these special into DB and displaying in the textarea.

    Thanks,

    Shiva
     
    shiva_rnm, Aug 15, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thats because the html page is not using an UTF8 charset but rather Western/Latin1 or some other 7-bit character set which simply does not have the space for the special characters.

    So two things you gota make sure you do.
    Set the character set of the HTML to UTF8
    Set the collation of the fields in the database to utf8

    From there normal queries should store the characters correctly.
     
    kblessinggr, Aug 15, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You'll probably also want to execute these queries before doing any other:

    SET CHARACTER SET utf8
    SET NAMES "utf8"

    Or if using mysqli :

    mysqli_set_charset('utf8');
     
    premiumscripts, Aug 15, 2009 IP
  4. shiva_rnm

    shiva_rnm Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi kblessinggr, thanks for ur reply ...
    My html page is in utf-8 and also DB column is utf8 ... if i go directly to DB and enter these special char they shown good in DB but not in my textarea (shown testing oe, Œ , ... instead of œ, Œ , …
    i dont know what is happening ..
     
    shiva_rnm, Aug 16, 2009 IP
  5. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Try:
    
    $textArea = htmlentities($textArea, ENT_QUOTES, "UTF-8")
    
    PHP:
     
    Gray Fox, Aug 17, 2009 IP
  6. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    how did Gray-fox suggestion resulted shiva about the html entities. I am interested in this topic since I had to convert all the databases, tables and field areas in the DB to utf8 as well the connection in the php script with the mysql_set_charset function so it can insert and fetch and take the information out of the DB and into the DB as well..
     
    co.ador, Aug 17, 2009 IP
  7. shiva_rnm

    shiva_rnm Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks Gray-fox for suggestion, I did
    $d->setDescription(stripslashes(utf8_decode(addslashes(htmlentities($description[$i], ENT_QUOTES, 'UTF-8', false)))));

    it shows everthing properly ... but each time while displaying i need to do {$desc|htmlspecialchars_decode} ....

    and the data in DB is fully encoded ....I feel its not the solution ... I just have problem with these special char
     
    shiva_rnm, Aug 19, 2009 IP