PHP/Python json_decode doesn´t display special characters like € - php

I got a json which is generated in a python program and looks like this:
{"0": {"ausschreiber": "Beispiel; Zeitarbeit GmbH", "beschreibung": "\r\nF\u00fcr unseren Kunden suchen wir motivierte studentische Aushilfen auf flexibler Stundenbasis (450\u0080-Basis)", "datum": "17.11.2016", "name": "Studentische Hilfskr\u00e4fte gesucht", "email": "info#hindi.de"}}
now i am decoding the json in my php program to get an associative array and display this on the website.
The Problem is that the special characters like the € char are not displayed but special chars like ö ä ü are displayed.
Here is the php program:
<?php
header('Content-Type: text/html; charset=utf-8');
function compare($old_data, $new_data){
$old_result = json_decode($old_data, true);
$new_result = json_decode($new_data, true);
echo $new_result[0]['beschreibung'];
}
function go4it(){
$db_data=json_content(); //creates the json from the Database
$crawler_data = file_get_contents('http://localhost/phppath/python_program.cgi'); //calls the cgi which returns the json
compare($db_data, $crawler_data);
}
go4it();
What i tried:
set the header to utf-8
$new_result = json_decode(utf8_encode($new data), true);
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("input_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
Thanks for your help!
EDIT 1
so it seems like the issue is located in the python program, thanks to #FranzGleichmann . I think the problem is with the encoding of the page where i get the content from. The page says it is ISO-8859-1 so i tried this:
url = 'https://www.example.com'
source_code = requests.get(url)
plain_text = source_code.text
plain_text.decode('iso-8859-1', 'ignore').encode('utf8', 'ignore')
print(plain_text.encoding)
but then i get the error: "UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 8496: ordinal not in range(128)"

it was a problem with the python script

Related

Convert Binary to File Using PHP

I'm using a service that gives you a wav file. this service gives me base64 binary code as a result. I want to convert it to a wav file.
I've been googling for it and couldn't find anything. here is my code :
$wsdl=' < url > ';//url to WSDL
$client = new SoapClient($wsdl);
$param=array(
'userName'=>' < my username> ',
'password'=>' < my password > ',
'messageId'=>1063716
); // parameters needed to download the file
try{
$res=$client->DownloadMessage($param) ;
$base64Binary = $res->DownloadMessageResult;
echo $base64Binary;
}catch(Exception $e){
echo '<pre>' ;
var_dump($e->getMessage());
echo '</pre>' ;
}
and the result of the echo is this:
RIFF&WAVEfmt #€>dataÞ%¯ÿ#HrÿvÿÿâÿÂÿ7Æÿ‚ÿžÿ€ÿÎÿÌÿQQÝV…‚© K 6(Iv7%ýÿñÿÃÿªÿÐÿ¦ÿÜÿWÿKÿ®ÿ¯ÿÝÿ”ÿ•ÿwÿ¹ÿ¶\JŸœñ{KH66þÿõÿõÿäÿªÿDÚÿ÷ÿªÿìÿÒÿNóÿØÿÈÿÝÿÄÿÞÿžÿ'Úÿ¾ÿÒÿYÿqÿ…ÿÌÿ×ÿÃÿµÿ¸ÿÉÿÏÿñÿŸ‰¿uÚÿ$x;^UÁÿ¾ÿÅÿ|ÿ­ÿ¤ÿøÿüÿÿ™ÿèÿªÿmÿ…ÿAÿ™ÿŒÿ0ÿÿˆÿB•ùÿ·ÿ†™ðjÖ=1µê}*|!<ÿ‘ÿNÿ|ÿ¦ÿÿÿ¼þ,ÿ(ÿÖÿÿyÿÇÿÕÿÒÿîÿy 0TOHƒ-Q$’‰kO>\¾µÇÿ¥ÿØÿÿ(¸ÿÁÿŸÿ÷ÿêÿœÿõÿsÿ¤Ùÿ#ôÿƒÿ[Ÿâÿ›ÿÝÿ;§ÿ,ÕÿMK¾ÿ<�EÎÿŒÿ©ÿfÿ²ÿ²ÿ¢ÿ¿ÿªÿóÿ0aãÂ~T¬íq]/.D*áÿÿ•ÿ`ÿoÿsÿˆÿ<�.ßÿaÞ[‘•kùÿ ÿhÿ:ÿóþ0ÿWÿšÿêÿ1|N©ÿÊÿßÿýÿ¿ÿ¸ÿSÿÝÿúÿ)°ÿ‰ÿâÿwÿÙÿ^ÿ¼ÿ­ÿ®ÿÕÿhóÿ¶ÿôÿe)DãÿØœˆ=o]¨˜1+ J»+;çÿÍÿÔÿg¤ÿÚÿÿÓÿÿàÿÖÿÍÿ?ÖÿÖÿD oöÿ}ÿ—ÿaÿ¤ÿ¨ÿvÿ·ÿ1ÿ¼ÿ”ÿíÿˆÿ09#°ÿC¨ÿ: ?`%_îÿJ*[dBãÿQëÿïÿüÿïÿÐÿcÿ›ÿ¼ÿøÿÕÿÇÿäÿÜÿH«ÿ¹ÿèÿÉ$΀aCMy2r3^ž<�ØÿHçÿ-†ÿŽÿ#ÿ%ÿBÿ‹ÿºÿ¡ÿ"éÿ÷ÿ«ÿçÿçÿ/öÿ¡ÿôÿ¸ÿõÿéÿrvgj%?²ÿÒÿÿöÿËÿ®ÿ‡ÿ<ÿ¼ÿ­ÿD1ŠcY+ Iuÿÿ04SÌÿ:<ÿXÿûþyÿFÿ÷ÿŒÿiÿÙÿŒÿòÿ¥ÿ ÏÿðÿÑÿhO#Òý¼» ¶&1\ÿgÿžÿªÿœÿûÿ#þÿ3 µûy(E„ÿ/¥ÿŸÿŒÿ2ÿ!ÿúþ_ÿÈþ¾ÿ·ÿpÿŒÿ:ÿøÿÝÿæÿãÿ_–±œ2ë•òÚË•xøÿÛÿåÿªÿîÿÎÿÃÿIÿ\ÿj·ÿ·ÿcÿËÿ<�=6xQ„R„=…ÿdÿœÿMÿ ýÿ‚Mü±PþÿžÿmÿƒÿNÿéÿ ÿOŒÿmÿVÿÿ$m›ûÿêÿ›ÿ2òþÕþvÿäÿþÿ{ÿûÿnÿ-Q\v[ÿÿ2ÿ!ÿ—þ´ÿDÿ8ÿ™ÿ*ÿäÿ)fJýŒ5hÈ3ÃJOVk/jÆ*<ˆv/\pÿÿçþ¨þ›þtþMþqþÀþIÿYÿBÿ¾ÿúÿB6t¥õßñÛ()¼ÿëk¢ÿj7“„ÿÿïÿýÿñÿ&ùÿÎÿcG¤ÿÈÿÀÿ²”ÿÞÿXÿ*ÿÿ,ÿ þ³þéþ¥¤wûÿq;æÿÿÀÿðÿEÇþ$ÿÿ­ÿ«ÆÿàÿŽÿwHUÿ1ÿvÿhÿ^ÿÿaþéþRÿÿµþÿ¡ÿÍÿrÿ„ÿaÿÀÿïÿ~ÿÃÿòÿ«TÓrb¿û‰ý¿Û}Iä|«}v¾o1Ñÿç;õÿûý<þzþ¾ýêüüü¿þ–\ÛÈé¤Z’%½ÿßý^ýÆýþdÿIž‚q_舶Á¾£þŸý°þdýêüÿ&¼:=o2ý;ÿ"þžþÖÈ^ÿü„û˜ýþbüWùø.úðû{üú…û¿šþö¹öòörùøØñô„üV¹¬ý&üôÙ¨û÷zü B¹ÿþŸÿœ¶}ÿóõàþŠþQô³â ºù7þ»ó0ý ýðä¡ÜåËôcÇ©è üÚõêÌî?öøò9òø‰°ö¶qÍÅmtî%¸|EùøÿFax¶/CÞÁ~ˆ(&&D(üKñ+÷OGëÔÖãlö‹úÁÿFö îåübî\ÞÐæNû³:T~4 ‰›þ%ä …ª¹ðÐîE_ÐûfúÑûýÞþ…ÿéÿÿLþIý ülüwüœý8þCz2…wÝý:O6'%êõÀè¿ñcû áSØÒï(¯]¢õ)ý÷|íáÚéIÿïb = Ëøºî9ð;úã s‘›!ï†`&üvÿÌTGÔáÿriþÀü2ü2ýÊý`üü-ÿV Mÿ¬ürüàü]ý(üÿû°üÿ–¬ÿÿLÿ÷ÿÿ'þÿÿwþ÷åþkG;Æ%Ýÿ®ìóã<ô`tæÁØðI"n ùìëõ õéeÜgàe÷´8MRüÍ{ÿ&ïsæ[ó~þmH¸¤2™ÿîûœþw†o†ÕÒ×6¦ á±þñýõüîüÿ²ÿÿÑÿêÿþþÂþþ¡ýýký¶ýÚþŒÿ)·ÿhÿ“þÖþëýÿNþÍ?ÿøìþòE9€$¦þîièô¾ü}áùØHóaÅ lÊûŒö˜Åõžã¿Û$á^õ‘ÓT[›'0qîcèô}ÿ‹ Ks1T]åYÎþ¿þL‡mΤ<ÿ´ªaÿÊü±þ€a#ÿËü$þ¼È×ýðú9üÁþ¡þý}ý˜ÿ§Lÿþ´ý¡ÿ zËþÜÿÇÿ®FŠvÿißfe)¼0cDûJðÝïúþÎîÖÃæåvŠˆîö1>éí’Þ3Ûjê« ÿ×þªöà Lù¸ì¬ñ YXÝ ýuì­ VØÿ'i+[Èê?‘ÿiþºÿž=€0M*ΣþŠüöûÈüÙüAý~ý‘þ)ÿšÿ‰þÙý(ý!ýý"ý¼ýþÉÿÉÿ/dÿδýµ ,P"|ö¹þ7ýãÝtï:ýÊ _ký÷ÿ" $Êñ_ç-æHðìøôÓò=ûõÆ[ücú×ÿåÐX[WdD MPsþÿ1{ñÔì#kf¦Sè#pÿ-ÿGµÿÃþÿmþœþþ¦ý0ýiý'ýý.ýâüŒýÃý&þ¯ýMþÄýºþQþ"ÿÕþÓÿÁÿ|½óŽ6!_ ?…amùØç‡ë%ñã÷×þ¦û´ú’‚Çÿ$úQò³ðó…ðOîÝñH÷0ý:ù#Ê ærúÕm Z6; tXÞóؽe㪎§ÁÈb¸ò‘âð¡s'¾|ÿdþ|ýý“ünüVüšü­ü#ýDýŒý–ý¦ýŽýbýPýñü"ýÂüeý ý?þ¼ý¡ÿ—þÚÂóÆ ·TRÁÿèùø‡õŽðRï»ï¨îäñSó"ôöø¯ø"û½ûûÎûgû1ûJûûúËúPýÙþ­çÊ* º BX!ó±Ç)#ƒÔ‚(fûµ%'öÀÿäþþ2ýœü/ü˜ûwû;û+û+ûNûWû†ûËûàûWüküý ýðýÏýùþ¹þÿpQÃì £¡Ž x]ÚÿÞûÿõãñ÷îÛê[ëSëçêÅìï=ñnõ¤ø¼úCýÿ ^Ò[uI£H}ÖY;÷ ØÇ —æ£5» bãFÂEŽ¼$ÿCþ8ýEüûâú_úBúúMúyúûQû.ügü:ýpý!þ#þÕþìþOÿ§ÿbžÁ\í Ñ~CË[7fúµõIò'íåëRëvé„êìÍíSñ‡õÕ÷ûüýXÿW°¨Ôùäë=é”ãÞ²Ägwï4,Ø· 3¬å-¬I G ÀÖ6<®ÿïý)ülúRùFø!÷ìöÓö®ö'÷[÷Ê÷2ø!ù)ù8úFúOûwûãüàü‰þÅþBÞ…rÂ~~ƒÇÙýGù¢õšìOè`ç×ã/çì¥ì+ñýõ‘ø>üVÿ2ý?üûõø"øBö õáörúþþ8ÓèQ…€îO¥Q×ó»:Íà$ ½_²ps èh³þý´üžüÛû%ü0üàûqûæúîøØ÷iöäô÷ó$ó®ò›ò&ôkôA÷øKûü´ÿŽÿ“" HÉKlç0”hú²ôåêðìºèÞîÚòÎóâ)ø¥³Éù•ùiô|éõæäUáÝèÔîô h r5`ˉ)ãû‹Üu¯d- šo4þj! Æþ ¥áýÅýñýþü¹üsü<ûUú#úø2÷ÅõÓôÍóËôØó5õ›õ7÷dø©úüJý}ÿNÿžn/ü^šº!øÙ K møMõ­æoßëíæõ…ü ÿ(ÿ• i]Zò4êé=äá‚åä+ëY÷úÓo-:g!obƶ bÚͪÚù‰uÄ.G—ó¹6ÛØ©ÄíT¡ÿtþ·ýåýüIûYùZøAø*ùIù¿ù¨ùµùSú]ûÜû5üüBüªý¹ýÙÿöþžKÿ€Mÿ…n% "=)ƒ8û÷8îÝéxåú×]ãÛïYlÇã6+úáõêýÜ°×±ÙaâØïXü°§€rAoÐõ¹ ‹a ¯7‰t‡¥ Ä rŽ®‡)qÔÿÍþeþ/2ÿÉþtýÐû2ûû%ü­ûaüûîûküþ-þÿþþþ‡þQÿcÿùþÒ+ÿÕòþÿÈ$u&¥(ç öû$ìœê‚å2êÃäTßòêª÷àÌ ÐþmóTì|ìŒæàWÝ^ãîDÿÙ…•š˜™Blä„ØŽ—%x\é’‚D20G³Ó“Â"‹ÐKŽr~»FR±,yÿçüýGû‘û”übü:ýæü†ýëü&þ£ý»ýtýýüý`ý{þ‹þNÿ¾Ïÿ +Mÿgà#Ò$À*2ïüòéRáSã"éŽîëéQïï÷ß|^#7þ ìßøà7åJèêëùñ¾ÿ‘—M,,Gybàæ[Ï?ö ÊAøÿ úÿ-0K›ôæN³»ú—ýÿ^ÿ%r|¸ÿ#ÿÆý'üeû7úJûªû£ý6ÿ’¢ÿïþ\þËýûýþðþIÿî×QSêÿáHþâ "4%»*ùýáÖ`ß³ê¼øbùú5úïîèú€älÕbÖ,äXöËI†F±êe¨þ6[ 3l î)ô¬+ËCýÿ÷ÿùÿøÿ*3OeÐþ‘˜eÖt°´È3Êÿý¤ýSÿ§þ¾ÿfýðü!üHüªýTýBýVü”úÌúüÜýÿ–ÿÓþÈý–þmÿPÞÌÿxƒ»=c ¸"“&Lîý+æOÜÂäüíú·ýþ-ü_þž®/ö-ëãåJíþ÷}ß3ýþ—UÒÆ › Ž]p}…Ñ’ZBÿÿõÿõÿõÿøÿûÿÿÿ/N–×lÃÖìwi>„%}ÿÿ‘ýÌü«üüüƒý0üoü³ú]úDúZúºûwüƒýìýsþaþÜþ”þ’ÿmÿ,$ø Ü­Nü¬²é9 QýÉîÝðäòøðùnúø¡öTøú¥ý)û”÷ƒñzí™íßðj÷Åü.þáýÔüùü}ÿÉ É 1lº”Ì Ô §”‰ƒÎ…I6 øÿöÿþÿ÷ÿþÿ÷ÿúÿ3S¢ê Œr‹r­uBqíÿ×ÿ*ÿšþ¼ýšý.ýý ý´üeüüäûÊûyüÙûýNýdþÿ’ÿ{!¿n ed–„ü}m YÙüª÷+ø›÷]úáøiù*ö¬öìöù<ûù®÷!óñ+ñó.÷ƒù$ûrû4üÖýúo©– Ž ¸ú Oê¹s’ ˜V%ýÿþÿøÿúÿöÿùÿõÿøÿöÿûÿûÿ'LËEâ©·›K›qþÛ:Ë÷×g¾ÿÅþ^þ/þØýƒý¡ü>ü¢û—ûžû#üŠüÖüý%ýuý¶ý;þµþ0ÿaÿÁÿ±ÿ3ùwÙuç^ ßÄ IH®îÿRýû¤÷cöÛõ¤õRöØöD÷Fö¡õÿô!õ öG÷YøÅøþùðúÏû±ý°ÿÓIÓÈ ž‘ £=JÇt#"þÿûÿúÿøÿ÷ÿöÿöÿôÿôÿöÿùÿ7k°7÷ÇÅÝ•¥›Ð‹Ü”oó3‘èT²ÿøþ}þ¸ý'ý üzügüLübügüœü«üýCý¦ýõýUþ„þ½þïþ5ÿkÿýÿ3à»dl«œ¾`Å3vþýû¿ùrøo÷’õ-ô¡ó˜ó3ôÛôfõÖõªö¯÷“ø²ùû²ü¦þ¯TªÚ¸ƒ¥—¿)ÂzN/ýÿüÿúÿùÿøÿ÷ÿöÿõÿ÷ÿýÿ#}ÍDâråDmqb/Þ~$Êc©T#úÿ°ÿ™ÿ¡ÿ“ÿ£ÿ¤ÿvÿfÿ^ÿCÿ?ÿ;ÿ%ÿÿÿõþýþÿ+ÿ9ÿcÿ|ÿÜÿøÖäÏ~U o·ö…·3áÿÿ«ýˆü©û®ú’ù×ørø4øJøUø…øÌø:ùÁùJúûÆû—ü¹ýíþâÿßÝ…ÝØvñsº~T6$ÿÿÿÿþÿþÿÿÿþÿýÿýÿüÿþÿ#:PaixŒ‡yreSKH>22* ýÿõÿíÿæÿÜÿÒÿÎÿÕÿÜÿ×ÿÙÿÞÿåÿêÿöÿ÷ÿøÿ6m#ÏûeÜ.„w íuõ¿o ÑŠ*ñÿÚÿ§ÿrÿ[ÿ/ÿ ÿÿãþ¤þ†þ€þwþ€þªþÕþÿNÿÿ·ÿ×ÿ6a€ï9ŸÕ³¯ÆT)¥¯ÿ„ÿQÿÿòþwþþþ(þQþ•þØþõþ¬þˆþšþNþþñýoý]ýõýrþÓþ!ÿ*ÿ"ÿ/ÿ4ÿBÿKÿ<ÿ!ÿÿÿúþÿþKÿ›ÿ«ÿ›ÿ¬ÿÙÿ×ÿÈÿêÿèÿÅÿÔÿÚÿ®ÿÿƒÿqÿ¥ÿh ¿ÐÕñߎNÙÿžÿÿaÿXÿ[ÿ?ÿ>ÿUÿPÿKÿFÿ:ÿMÿ–ÿÏÿÕÿüÿI…™™~aKH3ïÿ¦ÿ˜ÿ¨ÿšÿ‚ÿdÿOÿDÿIÿ=ÿ2ÿDÿ]ÿmÿyÿÿ{ÿ”ÿ½ÿÌÿÀÿ½ÿ¾ÿÐÿñÿûÿáÿ¾ÿ©ÿ¤ÿ©ÿ¢ÿ˜ÿžÿºÿÊÿËÿÑÿàÿúÿ#&%+I]f{–«¦”~zuaG5/-÷ÿíÿæÿÔÿ¾ÿ­ÿ›ÿÿŠÿ–ÿ¤ÿ°ÿ®ÿ«ÿ®ÿ²ÿÂÿÃÿÃÿÅÿµÿ¬ÿ¡ÿŒÿÿ›ÿ¡ÿ›ÿ’ÿÿžÿ°ÿ¶ÿÇÿÒÿÜÿêÿýÿüÿ!" ÷ÿ÷ÿýÿóÿëÿîÿèÿßÿÞÿÌÿÀÿÇÿÀÿ½ÿÊÿÕÿÕÿØÿÕÿÕÿÕÿØÿãÿãÿáÿÝÿæÿ÷ÿ (28<�AGJOPV\]WXVUTD846;1&"ôÿæÿïÿøÿÿÿÿÿõÿìÿçÿïÿ÷ÿñÿèÿäÿèÿèÿÝÿËÿÑÿÛÿÜÿçÿêÿöÿ'75486% *.$ìÿÔÿÁÿ»ÿ¸ÿ¸ÿÀÿÈÿ×ÿáÿðÿüÿýÿ þÿþÿúÿïÿèÿïÿðÿêÿíÿñÿðÿñÿóÿïÿùÿ-#D7.öÿíÿéÿåÿêÿíÿàÿåÿñÿúÿ #),-7AB:.($! þÿóÿéÿïÿîÿíÿõÿÿÿúÿõÿðÿéÿæÿäÿèÿëÿïÿéÿçÿãÿßÿïÿîÿèÿìÿñÿôÿõÿñÿòÿïÿíÿîÿìÿòÿÿÿûÿûÿ ÿÿòÿüÿ þÿüÿùÿüÿÿÿùÿöÿöÿòÿïÿæÿáÿÞÿÜÿàÿéÿïÿúÿ ÿÿ õÿõÿóÿñÿíÿíÿõÿøÿ ùÿöÿúÿ "&ýÿüÿþÿÿÿüÿúÿùÿ÷ÿòÿëÿóÿ÷ÿûÿøÿñÿîÿðÿóÿòÿåÿêÿñÿñÿùÿûÿÿÿÿÿùÿÿÿùÿúÿ ÿÿ÷ÿîÿìÿïÿôÿúÿñÿìÿñÿòÿéÿëÿóÿòÿçÿâÿèÿèÿñÿþÿ þÿüÿóÿìÿçÿðÿ÷ÿ øÿêÿßÿßÿåÿìÿòÿîÿùÿ$ üÿúÿ÷ÿõÿüÿûÿþÿýÿúÿüÿøÿùÿÿÿúÿýÿüÿõÿðÿêÿêÿíÿíÿëÿðÿóÿñÿñÿôÿôÿïÿîÿïÿøÿ ñÿïÿéÿñÿþÿ÷ÿþÿþÿûÿûÿúÿûÿüÿüÿóÿóÿæÿçÿïÿøÿüÿûÿ ÿÿüÿûÿøÿîÿñÿóÿôÿýÿúÿûÿÿÿûÿýÿ þÿñÿóÿùÿ÷ÿðÿèÿàÿãÿæÿæÿðÿøÿöÿ÷ÿ ÿÿûÿôÿéÿâÿÛÿØÿÜÿÞÿãÿíÿóÿøÿùÿøÿýÿÿÿûÿöÿüÿ ÿÿùÿ÷ÿüÿ!! üÿþÿ þÿúÿíÿéÿíÿìÿïÿðÿïÿòÿóÿ÷ÿúÿýÿ%'" ÿÿûÿùÿðÿîÿðÿêÿçÿèÿéÿïÿíÿòÿòÿòÿñÿëÿðÿîÿòÿúÿ ÿÿýÿûÿ÷ÿîÿîÿòÿüÿÿÿ ÿÿýÿûÿøÿõÿîÿèÿèÿâÿØÿ×ÿÚÿÝÿàÿæÿëÿîÿòÿõÿûÿÿÿ üÿõÿòÿéÿéÿêÿëÿëÿêÿëÿëÿâÿâÿâÿáÿêÿçÿèÿéÿîÿïÿ÷ÿÿÿ ûÿõÿúÿùÿøÿôÿõÿóÿôÿøÿøÿûÿúÿøÿøÿúÿýÿÿÿ ÿÿúÿøÿüÿúÿòÿõÿøÿüÿþÿ úÿþÿüÿüÿüÿõÿóÿðÿëÿãÿÞÿâÿàÿåÿæÿåÿéÿóÿüÿ ýÿùÿùÿïÿêÿêÿèÿçÿçÿçÿëÿïÿòÿôÿòÿòÿïÿïÿñÿöÿüÿýÿÿÿÿÿþÿ÷ÿóÿñÿòÿðÿïÿðÿîÿîÿðÿõÿñÿõÿúÿûÿúÿ÷ÿøÿõÿôÿóÿ÷ÿøÿ! ÿÿüÿüÿÿÿÿÿÿÿþÿüÿýÿþÿÿÿþÿþÿùÿóÿóÿóÿöÿöÿóÿëÿìÿìÿéÿîÿõÿ÷ÿöÿùÿ÷ÿ÷ÿûÿþÿýÿ þÿüÿúÿøÿ÷ÿöÿôÿôÿñÿòÿóÿùÿøÿøÿüÿöÿûÿ ÿÿúÿõÿöÿ÷ÿùÿöÿøÿôÿìÿäÿçÿæÿèÿïÿêÿíÿñÿ÷ÿúÿÿÿÿÿ÷ÿøÿúÿýÿ""'%! üÿöÿôÿôÿöÿôÿûÿûÿýÿ
is this a base 64 binary? if it is, how to convert it to a wav file?
The string you're echoing looks like a plain wav stream. Just write it to a file without any decoding and you'll end up with a wav file. Be sure to use binary mode when writing the file.
$ptr = fopen("file.wav", 'wb');
fwrite($ptr, $e->getMessage());
fclose($ptr);
Wav header info: https://en.wikipedia.org/wiki/WAV#RIFF_WAVE
If the base64 encoded data already represents an MP3 file, it should be as easy as decoding the base64 data and storing it in a file:
file_put_contents('audio.mp3', base64_decode($base64Binary));

PHP output JSON Web Service charset UTF-8 error

I am hosting a web service in JSON output by PHP.
I have Hebrew data set in DB and I am posting this as an output to Web service.
When I post the data initially it output the result as follows:
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ×רמה ×™×–×•× ×•×‘×™× ×•×™ בע"מ",
"cargo":"×ברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
But this "×ברר" can be readable by Android/Iphone parser and convert it to original Hebrew. But i faced Error in "name": "טר ×רמה ×™×–×•× ×•×‘×™× ×•×™ בע"מ",. where " is in between the string so the JSON is not valid and shows error!
To Over come this issue I used UTF-8 to convert "×ברר" this to Hebrew "נברר". But in this case too the problem remains same:
PHP:
header('Content-type: text/html; charset=UTF-8');
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ארמה יזום ובינוי בע"מ",
"cargo":"נברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
But still the problem remains:
Also in some case I am getting this � because of using UTF-8
"name":"מחצבות כפר גלעדי-חומרי מ�"
How can I overcome this issue?
Is there any other specific encode I need to use?
Note: The data cannot be changes in Database The solution should be while output to JSON.
How the data stored in DB is shown below:
name
מחצבות כפר גלעדי-חומרי מ×
My PHP Script which output JSON:
<?php
//My DB connection and Query comes here
$jsontext = '{"tasklist":[';
while($row = mysql_fetch_array($queryExe)){
$jsontext .= '{"customerID":"'.$row['AUTO_ID'].'",';
$jsontext .='"name":"'.$row['Customer_Name'].'",';
$jsontext .='"cargo":"'.$row['Type_of_Cargo'].'",';
$jsontext .='"destination":"'.$row['Destination'].'",';
$jsontext .='"quantity":"'.$row['Quantity'].'",';
$jsontext .='"startdate":"'.$row['startdate'].'"},';
}
$jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
$jsontext .= "]}";
header('Content-type: text/html; charset=UTF-8');
//Output the final JSON
echo $jsontext;
?>
Thank you for your help in advance!
Was the question clear? to understand my issue.
If your db-field is utf8 you should fist do:
mysql_query("SET NAMES 'utf8'");
You should always do the 'SET NAMES...' before inserting your data, too.
Be sure that you really stored utf8 encoded strings!
then do your query:
mysql_query($your_query);
$array = array("tasklist"=>array());
while($row = mysql_fetch_array($queryExe)){
$a = array();
$a["customerID"] = $row['AUTO_ID'];
$a["name"] = $row['Customer_Name'];
$a["cargo"] = $row['Type_of_Cargo'];
$a["destination"] = $row['Destination'];
$a["quantity"] = $row['Quantity'];
$a["startdate"] = $row['startdate'];
$array["tasklist"][] = $a;
}
header("Content-type: application/json; charset=utf-8");
echo json_encode($array);
exit();
i've made the experience that these is not enough when the servers default charset is for example iso. In that case i need to do the following in my .htaccess:
AddDefaultCharset utf-8
You should change your code to use json_encode. You need to pass it properly utf8 encoded data.
If you are using MySQL you can try running the following before your query to get your data.
SET NAMES 'utf8';
You can also look into using utf8_encode.
From http://www.php.net/manual/en/function.json-encode.php#100565
That said, quotes " will produce invalid JSON, but this is only an issue if you're using json_encode() and just expect PHP to magically escape your quotes. You need to do the escaping yourself.
May be you can replace " with \" , i guess it will solve the issue.
Source : PHP JSON String, escape Double Quotes for JS output

Delphi, MSXML2.XMLHTTP, PHP and Win-1250 charset encoding

Hoi!
I trying to make a webservice in Windows.
The client is Delphi 6, with MSXML2.XMLHTTP call, and other side is PHP.
First I tested: can I receive hungarian XML?
The PHP source was UTF-8 encoded file (PSPAD).
$s = 'alma árvíztűrő tükörfúrógép beta';
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$m = $doc->createElement('package');
$doc->appendChild($m);
$n = $doc->createElement('Msg');
$m->appendChild($n);
$n->nodeValue = $s;
$xs = $doc->saveXML();
header('Content-Type: text/xml');
echo($xs);
This package I fully got in Delphi side, the accents are ok.
So then I tried to inject data from xml (post xml to php with accents).
global $HTTP_RAW_POST_DATA;
$xmlstr = $HTTP_RAW_POST_DATA;
$xml = new SimpleXMLElement($xmlstr);
$msg = $xml->msg;
#$msg = 'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP';
Ok, I got the "msg" field, but nevertheless I trying to convert it, everytime I got some convert notice, and the result is not same as when I set the variable directly...
The debug is:
echo(utfCharToNumber($sinput).'<br>');
echo(utfCharToNumber($sdefined).'<br>');
Input: 195[ ]8286195141908419717682197[ ]328419
Defined: 195[129]8286195141908419717682197[144]328419
Input: 5156751951508270195154821951477119513780<br>
Defined: 5156751951508270195154821951477119513780<br>
As you see that two holes I have in the variable when I converted the input from MSXML2.
I really don't understand this.
I cannot reproduce same XML output from get the data from input XML as when I set directly in PHP code...
Why?
Thanks for your every help, idea, link, document, little example!
dd
Since you haven't included Delphi source, I suspect you're posting data straight from a string as content body of the request, which is encoded in the current ANSI encoding by default in Delphi 6. I advise you either use Utf8Encode on the string before you add this as the request's body data, or add a 'Content-encoding' request header with the name of the ANSI encoding (if I remember correctly GetLocaleInfo could give you this).
The source of the problem was the Delphi code.
Priorly I used AnsiToUTF8 to encode the XML text.
But the COM object is uses UTF16 as I think.
The working code is this:
procedure TForm1.Button4Click(Sender: TObject);
var
mhttp : variant;
ws : WideString;
tosend : OleVariant;
xml : TXMLDocument;
n : IXMLNode;
begin
mhttp := CreateOleObject('MSXML2.XMLHTTP');
mhttp.Open('POST', 'http://127.0.0.1/test_xmlgen.php', False);
xml := CreateANewDocument(Self, '', 'a');
n := xml.DocumentElement.AddChild('msg');
n.NodeValue := 'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP';
xml.SaveToXML(ws);
tosend := ws;
mhttp.send(tosend);
Memo1.Lines.Text :=
IntToStr(mhttp.Status) + #13 +
mhttp.responseText + #13;
end;
This can resend the XML I sent - with good accents.
Thanks for your help:
dd

How to convert 'u00e9' into a utf8 char, in mysql or php?

Im doing some data cleansing on some messy data which is being imported into mysql.
The data contains 'pseudo' unicode chars, which are actually embedded into the strings as 'u00e9' etc.
So one field might be.. 'Jalostotitlu00e1n'
I need to rip out that clumsy 'u00e1n' and replace it with the corresponding utf character
I can do this in either mysql, using substring and CHR maybe, but Im preprocssing the data via PHP, so I could do it there also.
I already know all about how to configure mysql and php to work with utf data. The problem is really just in the source data Im importing.
Thanks
/*
Function php for convert utf8 html to ansi
*/
public static function Utf8_ansi($valor='') {
$utf8_ansi2 = array(
"\u00c0" =>"À",
"\u00c1" =>"Á",
"\u00c2" =>"Â",
"\u00c3" =>"Ã",
"\u00c4" =>"Ä",
"\u00c5" =>"Å",
"\u00c6" =>"Æ",
"\u00c7" =>"Ç",
"\u00c8" =>"È",
"\u00c9" =>"É",
"\u00ca" =>"Ê",
"\u00cb" =>"Ë",
"\u00cc" =>"Ì",
"\u00cd" =>"Í",
"\u00ce" =>"Î",
"\u00cf" =>"Ï",
"\u00d1" =>"Ñ",
"\u00d2" =>"Ò",
"\u00d3" =>"Ó",
"\u00d4" =>"Ô",
"\u00d5" =>"Õ",
"\u00d6" =>"Ö",
"\u00d8" =>"Ø",
"\u00d9" =>"Ù",
"\u00da" =>"Ú",
"\u00db" =>"Û",
"\u00dc" =>"Ü",
"\u00dd" =>"Ý",
"\u00df" =>"ß",
"\u00e0" =>"à",
"\u00e1" =>"á",
"\u00e2" =>"â",
"\u00e3" =>"ã",
"\u00e4" =>"ä",
"\u00e5" =>"å",
"\u00e6" =>"æ",
"\u00e7" =>"ç",
"\u00e8" =>"è",
"\u00e9" =>"é",
"\u00ea" =>"ê",
"\u00eb" =>"ë",
"\u00ec" =>"ì",
"\u00ed" =>"í",
"\u00ee" =>"î",
"\u00ef" =>"ï",
"\u00f0" =>"ð",
"\u00f1" =>"ñ",
"\u00f2" =>"ò",
"\u00f3" =>"ó",
"\u00f4" =>"ô",
"\u00f5" =>"õ",
"\u00f6" =>"ö",
"\u00f8" =>"ø",
"\u00f9" =>"ù",
"\u00fa" =>"ú",
"\u00fb" =>"û",
"\u00fc" =>"ü",
"\u00fd" =>"ý",
"\u00ff" =>"ÿ");
return strtr($valor, $utf8_ansi2);
}
There's a way. Replace all uXXXX with their HTML representation and do an html_entity_decode()
I.e. echo html_entity_decode("Jalostotitlán");
Every UTF character in the form u1234 could be printed in HTML as ሴ. But doing a replace is quite hard, because there could be much false positives if there is no other char that identifies the beginning of an UTF sequence. A simple regex could be
preg_replace('/u([\da-fA-F]{4})/', '&#x\1;', $str)
My twitter timeline script returns the special characters like é into \u00e9 so I stripped the backslash and used #rubbude his preg_replace.
// Fix uxxxx charcoding to html
$text = "De #Haarstichting is h\u00e9t medium voor alles Into: De #Haarstichting is hét medium voor alles";
$str = str_replace('\u','u',$text);
$str_replaced = preg_replace('/u([\da-fA-F]{4})/', '&#x\1;', $str);
echo $str_replaced;
It workes for me and it turns:
De #Haarstichting is h\u00e9t medium voor alles
Into:
De #Haarstichting is hét medium voor alles

json_decode returns NULL after webservice call [duplicate]

This question already has answers here:
PHP json_decode() returns NULL with seemingly valid JSON?
(29 answers)
Closed 4 months ago.
There is a strange behaviour with json_encode and json_decode and I can't find a solution:
My php application calls a php web service. The webservice returns json that looks like this:
var_dump($foo):
string(62) "{"action":"set","user":"123123123123","status":"OK"}"
now I like to decode the json in my application:
$data = json_decode($foo, true)
but it returns NULL:
var_dump($data):
NULL
I use php5.
The Content-Type of the response from the webservice: "text/html; charset=utf-8" (also tried to use "application/json; charset=utf-8")
What could be the reason?
Well, i had a similar issue and the problems was the PHP magic quotes in the server... here is my solution:
if(get_magic_quotes_gpc()){
$param = stripslashes($_POST['param']);
}else{
$param = $_POST['param'];
}
$param = json_decode($param,true);
EDIT:
Just did some quick inspection of the string provided by the OP. The small "character" in front of the curly brace is a UTF-8 B(yte) O(rder) M(ark) 0xEF 0xBB 0xBF. I don't know why this byte sequence is displayed as  here.
Essentially the system you aquire the data from sends it encoded in UTF-8 with a BOM preceding the data. You should remove the first three bytes from the string before you throw it into json_decode() (a substr($string, 3) will do).
string(62) "{"action":"set","user":"123123123123","status":"OK"}"
^
|
This is the UTF-8 BOM
As Kuroki Kaze discovered, this character surely is the reason why json_decode fails. The string in its given form is not correctly a JSON formated structure (see RFC 4627)
Print the last json error when debugging.
json_decode( $so, true, 9 );
$json_errors = array(
JSON_ERROR_NONE => 'No error has occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
);
echo 'Last error : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
Also use the json.stringify() function to double check your JSON syntax.
None of the solutions above worked for me, but html_entity_decode($json_string) did the trick
Try this
$foo = utf8_encode($foo);
$data = json_decode($foo, true);
make sure that if you sent the data by POST / GET, the server has not escape the quotes
$my_array = json_decode(str_replace ('\"','"', $json_string), true);
"{"action":"set","user":"123123123123","status":"OK"}"
This little apostrophe in the beginning - what is it? First symbol after the doublequote.
I had the similar problem in a live site. In my local site it was working fine. For fixing the same I Just have added the below code
json_decode(stripslashes($_GET['arr']));
I just put this
$result = mb_convert_encoding($result,'UTF-8','UTF-8');
$result = json_decode($result);
and it's working
Yesterday I spent 2 hours on checking and fixing that error finally I found that in JSON string that I wanted to decode were '\' slashes. So the logical thing to do is to use stripslashes function or something similiar to different PL.
Of course the best way is sill to print this var out and see what it becomes after json_decode, if it is null you can also use json_last_error() function to determine the error it will return integer but here are those int described:
0 = JSON_ERROR_NONE
1 = JSON_ERROR_DEPTH
2 = JSON_ERROR_STATE_MISMATCH
3 = JSON_ERROR_CTRL_CHAR
4 = JSON_ERROR_SYNTAX
5 = JSON_ERROR_UTF8
In my case I got output of json_last_error() as number 4 so it is JSON_ERROR_SYNTAX. Then I went and take a look into the string it self which I wanted to convert and it had in last line:
'\'title\' error ...'
After that is really just an easy fix.
$json = json_decode(stripslashes($response));
if (json_last_error() == 0) { // you've got an object in $json}
I had such problem with storage json-string in MySQL.
Don't really know why, but using htmlspecialchars_decode berofe json_decode resolved problem.
Non of these solutions worked for me.
What DID eventually work was checking the string encoding by saving it to a local file and opening with Notepad++.
I found out it was 'UTF-16', so I was able to convert it this way:
$str = mb_convert_encoding($str,'UTF-8','UTF-16');
Maybe you use thing as $ ${: these chars should be quoted.
I was having this problem, when I was calling a soap method to obtain my data, and then return a json string, when I tried to do json_decode I just keep getting null.
Since I was using nusoap to do the soap call I tried to just return json string and now I could do a json_decode, since I really neaded to get my data with a SOAP call, what I did was add ob_start() before include nusoap, id did my call genereate json string, and then before returning my json string I did ob_end_clean(), and GOT MY PROBLEM FIXED :)
EXAMPLE
//HRT - SIGNED
//20130116
//verifica se um num assoc deco é valido
ob_start();
require('/nusoap.php');
$aResponse['SimpleIsMemberResult']['IsMember'] = FALSE;
if(!empty($iNumAssociadoTmp))
{
try
{
$client = new soapclientNusoap(PartnerService.svc?wsdl',
array(
// OPTS
'trace' => 0,
'exceptions' => false,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
//MENSAGEM A ENVIAR
$sMensagem1 = '
<SimpleIsMember>
<request>
<CheckDigit>'.$iCheckDigitAssociado.'</CheckDigit>
<Country>Portugal</Country>
<MemberNumber">'.$iNumAssociadoDeco.'</MemberNumber>
</request>
</SimpleIsMember>';
$aResponse = $client->call('SimpleIsMember',$sMensagem1);
$aData = array('dados'=>$aResponse->xpto, 'success'=>$aResponse->example);
}
}
ob_end_clean();
return json_encode($aData);
I don't know Why?
But this work:
$out = curl_exec($curl);
$out = utf8_encode($out);
$out = str_replace("?", "", $out);
if (substr($out,1,1)!='{'){
$out = substr($out,3);
}
$arResult["questions"] = json_decode($out,true);
without utf8_encode() - Don't work
Check the encoding of your file. I was using netbeans and had to use iso windows 1252 encoding for an old project and netbeans was using this encoding since then for every new file. json_decode will then return NULL. Saving the file again with UTF-8 encoding solved the problem for me.
In Notepad++, select Encoding (from the top menu) and then ensure that "Encode in UTF-8" is selected.
This will display any characters that shouldn't be in your json that would cause json_decode to fail.
Try using json_encode on the string prior to using json_decode... idk if will work for you but it did for me... I'm using laravel 4 ajaxing through a route param.
$username = "{username: john}";
public function getAjaxSearchName($username)
{
$username = json_encode($username);
die(var_dump(json_decode($username, true)));
}
You should try out json_last_error_msg(). It will give you the error message and tell you what is wrong. It was introduced in PHP 5.5.
$foo = "{"action":"set","user":"123123123123","status":"OK"}";
$data = json_decode($foo, true);
if($data == null) {
throw new Exception('Decoding JSON failed with the following message: '
. json_last_error_msg());
}
// ... JSON decode was good => Let's use the data
Before applying PHP related solutions, validate your JSON format. That may be the problem. Try below online JSON format validator. If your JSON format is invalid, correct it first, because PHP doesn't decode invalid JSON strings.
https://jsonformatter.org/
Laravel specific answer:
I got the same issue in Laravel. And this did the trick for me
$result = json_decode($result->getContent(), true);
In my case, when I was printing to the screen, json was fine and I copied and decode with json_deocode() function. It was working fine. But, when I was trying to put jsonString directly in the function, it was returning null because quotes were coming like these ". So I used htmlspecialchars_decode() function and now it is working fine.
I am new here, so if I am making any mistakes in writing answer then sorry for that. I hope it'll help somebody.
Sometimes the problem is generated when the content is compressed, so adding the Accept-Encoding: identity header can solve the problem without having to wrangle with the response.
$opts = array(
'http' =>
array(
'header' =>
array(
'Accept-Encoding: identity',
),
),
);
$context = stream_context_create($opts);
$contents = file_get_contents('URL', false, $context);
i had a similar problem, got it to work after adding '' (single quotes) around the json_encode string. Following from my js file:
var myJsVar = <?php echo json_encode($var); ?> ; -------> NOT WORKING
var myJsVar = '<?php echo json_encode($var); ?>' ; -------> WORKING
just thought of posting it in case someone stumbles upon this post like me :)

Categories