I convert string encoding from wide utf8 to limited encoding cp1251. I need to preserve some characters not included into cp1251.
In python 2.x there is a special function, which during encoding conversion replaces impossible characters with html-entities:
# -*- coding: utf-8 -*-
s_in = "Ø 125 mm".decode('utf8')
s_out = s_in.encode('cp1251', 'xmlcharrefreplace')
print s_out # prints Ø 125 mm
Is there any ready-to-use func/lib in PHP to do the task?
My code is:
<?php
$in = 'Ø 125 mm';
$out = mb_convert_encoding($in, 'cp1251', 'utf8');
echo $out; // prints ? 125 mm
By using
iconv()function inPHPyou can convert string from one to another encoded scheme. Example:For complete description see link: http://php.net/manual/en/function.iconv.php