json - PHP4: Json_encode method which accepts multi byte chars -



json - PHP4: Json_encode method which accepts multi byte chars -

in company have webservice zu send info old projects pretty new ones. old projects run php4.4 has natively no json_encode method. used pear class service_json instead. http://www.abeautifulsite.net/using-json-encode-and-json-decode-in-php4/

today, found out, class can not deal multi byte chars because extensively uses ord() in order charcodes string , replace chars. there no mb_ord() implementation, not in newer php versions. uses $string{$index} access char @ index, i'm not sure if supports multi byte chars.

//excerpt encode() method // strings expected in ascii or utf-8 format $ascii = ''; $strlen_var = $this->strlen8($var); /* * iterate on every character in string, * escaping slash or encoding utf-8 necessary */ ($c = 0; $c < $strlen_var; ++$c) { $ord_var_c = ord($var{$c}); //here comes switch replaces chars according o hex code , writes them $ascii

we call

$service_json = new service_json(); $data = $service_json->encode('marktplatz, hauptstraße, endingen'); echo $data; //prints "marktplatz, hauptstra\u00dfe, endinge". n missing

we solved problem setting webservice receives serialised arrays , returns json_encoded string. service runs on modern mahine, uses php5.4. "solutions pretty awkward , should improve one. have idea?

problem description

german umlauts replaced properly. string cutting of @ end because ord returns wrong chars. . mb_strlen() not alter anything, gives same length strlen in case.

input string "marktplatz, hauptstraße, endingen", n @ end cutting off. ß correctly encoded \u00df. every umlaut cuts of 1 more char @ end.

it's possible reason our old database encoding, replacement works correctly guess it's ord() method.

a colleague found out that

mb_strlen($var, 'ascii');

solves problem. had older lib version in utilize used simple mb_strlen. prepare seems same mb_convert_encoding();

problem solved now. give thanks much help!

json encoding php4 multibyte

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -