e-mail
Home > Computers > PHP - substr and UTF-8

PHP - substr and UTF-8

If you have a problem working with strings in PHP UTF-8 - the problem is probably that substr goes by the number of bits and not by the number of characters. In UTF-8 has more bits each character, so it then hacking away with chain hooks and accents more than it should (today it cost me 2 hours searching in the code before I figured out that the error is not on my receiver). This can solve their own functions.

Functions such as piko_substr

function piko_substr($text, $odkud, $kam) { $temp = iconv("iso8859-2", "utf-8", substr(iconv("utf-8", "iso8859-2", $text),$odkud,$kam)); return($temp); } 
marketing
Tags: , , feed Categories: Computer Tags: , , feed
  1. CZIP
    April 15th, 2011 at 11:39 | # 1

    What about mb_substr ();

  2. Lukas Satin
    July 3rd, 2011 at 15:32 | # 2

    Mb_substr alone () sometimes does not work and the top is necessary to add:
    mb_internal_encoding ("UTF-8");
    mb_http_output ("UTF-8");
    ob_start ('mb_output_handler');

    Make it the same as those rows with iconv ...

  1. No Trackbacks yet.
IMPORTANT! To Be Able to proceed, you need to solve the simple math seuraavilla (so we know That you are a human) :-)

What is 9 + 13?
Please leave These two fields as-is:

Spam Protection by WP-SpamFree

search
tour
service