UTF- and sql database isuue

This might now be the right forum for this issue but i did browse around before posting these for apprepriate website but anyways, suggestions little proble i’ve been facing. Relating to a database to get say news. Media are posted by users and end users can post applying unicode(UTF-8)
somewhere in my page we need to display the all the list such news, not whole content material but say 300 charecters of each one news. With INCI char its no problem you can get using substr within the query for any desired availablility of charecters but! because we dont’ know whether this type of news is with INCII or seemed to be posted using unicode, as well as becuase unicode charecters require 5or 6 incii char in order to display one charecter, We can not use substr function inside query to find 300 charecters on the news, this would likely give me merely about 40 as well as 50 valid unicode chars if displayed.
I am pretty sure there’s a way to diagnose unicode chars in the database and fetch desired amount of such charecters and I am hoping one of an individual guys could suggest me the way to do it. Thank you.

A method directly inside database would often be specific to just about every engine; some advisors have string length functions that work on multibyte characters and several don’t.

If it’s okay to obtain the entire stringed back, and in case you are using PHP, you can use phpfunctionmb_strlen/phpfunction (multibyte chain length).

BTW, UTF-8 is about two bytes a character.

Thank you for suggestion. Relating to done some striving with mb_strlen() nonetheless unsuccessfull to impliment it and find the right end result. If you may give me code example i might much appreciate By way of example say you do have a post body,
$body = $row’body’; fetched through database
now how do you get 200 charecters only, whether this $body was in unicode or ancii
In addition, is there ways to get only TWO HUNDRED charecters(whether unicode or maybe ancii) from database
Do you think you’re sure unicode should be 2 bytes The language my business is using for instance one char is actually printed as; 2345 something similar to that, just to printing one charecter of that language in unicode. I am only assuming it would more than not one but two bytes.
once i fetch 200 chars out of database, it may get 200 yet when it posters one char; 2343 = A SINGLE unicode char, 200/ 5 VARIOUS = 50 for this reason i see simply 50 unicode charecters.
gives thanks.

This entry was posted in Web Design and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *