php - Converting XML data to ISO-8859-1 for API call POST data -
i've got xml data i'm using post idibu api (job board api in uk). i've done successful call test post data. here is:
xml_text=%3c%3fxml+version%3d%221.0%22+encoding%3d%22utf-8%22%3f%3e%0d%0a%3cidibu%3e%0d%0a%3cmethod%3eadd%3c%2fmethod%3e%0d%0a%3cconfig%3e%0d%0a%3cshow_durations%3eno%3c%2fshow_durations%3e%0d%0a%3ccompletionurl%3eemail%3c%2fcompletionurl%3e%0d%0a%3cadvertcompletionemail%3ebob%40bob.com%3c%2fadvertcompletionemail%3e%0d%0a%3clockboards%3eyes%3c%2flockboards%3e%0d%0a%3credirecturl%3ehttp%3a%2f%2fwww.google.com+%3c%2fredirecturl%3e%0d%0a%3cvalidate_level%3ewarning%3c%2fvalidate_level%3e%0d%0a%3c%2fconfig%3e%0d%0a%3cjob%3e%0d%0a%3ctitle%3e%3c%21%5bcdata%5bxml+v+3+test%2c+please+ignore+special+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+-+%3a+%3b+_+%2b+%27+%22+%80%5d%5d%3e%3c%2ftitle%3e%0d%0a%3creference%3eabc123456789%3c%2freference%3e%0d%0a%3cdescription%3e%3c%21%5bcdata%5b%3cb%3especial+te+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+%2f+-+%3a+%3b+_+%2b+%27+%22+%27+here+euro+%80+%0d%0abasic+te+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+%2f+-+%3a+%3b+_+%2b+%27+%22+%27+%80+%0d%0aspecial+te+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+%2f+-+%3a+%3b+_+%2b+%27+%22+%27+%80+%0d%0a%0d%0a+%0d%0a+special+te+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+%2f+-+%3a+%3b+_+%2b+%27+%22+%27+%80+%0d%0abasic+te+%a3+%24+%26+%25+%40+%21+%3f+.+%2c+%3d+%29+%28+%2f+-+%3a+%3b+_+%2b+%27+%22+%27+%80+%0d%0a%0d%0a+%96+%96+%92+%27+%95+++++++%2c+%09%2c+%95+%b7+%93+%94+%d8+%85+%a8+%a6+%27+%3a+%27+%83+%e1+%91+%ba+%a1+%a7+%e9+%d7+%87+%27+%3a+%27+%27+%c7+%bd+%84+h+%ae+%97+%ac+%83+%e1+%99%3c%2fb%3e%5d%5d%3e%3c%2fdescription%3e%0d%0a%3csender%3e%0d%0a%3cname%3esteve%3c%2fname%3e%0d%0a%3clastname%3erogers%3c%2flastname%3e%0d%0a%3cemail%3etest%40mail.net%3c%2femail%3e%0d%0a%3ccompany%3eone+world+market%3c%2fcompany%3e%0d%0a%3cphone%3e44+%280%29+111-1111111%3c%2fphone%3e%0d%0a%3cwww%3ehttp%3a%2f%2fuk.idibu.com+%3c%2fwww%3e%0d%0a%3ccountry%3euk%3c%2fcountry%3e%0d%0a%3cpostcode%3e020+1111+1111%3c%2fpostcode%3e%0d%0a%3c%2fsender%3e%0d%0a%3ccategory+id%3d%2221%22+%2f%3e%0d%0a%3clocation+id%3d%228%22+%2f%3e%0d%0a%3csublocation+id%3d%22668%22+%2f%3e%0d%0a%3cjobtype+id%3d%222%22+%2f%3e%0d%0a%3cjob_time%3e2%3c%2fjob_time%3e%0d%0a%3cstartdate%3e2011-11-26%3c%2fstartdate%3e%0d%0a%3cduration%3efull+time%3c%2fduration%3e%0d%0a%3csalarymin%3e20000%3c%2fsalarymin%3e%0d%0a%3csalarymax%3e25000%3c%2fsalarymax%3e%0d%0a%3csalaryper+value%3d%22annum%22+%2f%3e%0d%0a%3csalaryoverride%3esalary+override+test+test%3c%2fsalaryoverride%3e%0d%0a%3ccurrency%3egbp%3c%2fcurrency%3e%0d%0a%3cpublish%3e2011-11-26%3c%2fpublish%3e%0d%0a%3cposts%3e%0d%0a%3cboard+id%3d%22517%22%3e%0d%0a%3cextrafield+name%3d%22idibudts_cat%22%3e3%3c%2fextrafield%3e%0d%0a%3cduration+days%3d%227%22+%2f%3e%0d%0a%3c%2fboard%3e%0d%0a%3c%2fposts%3e%0d%0a%3c%2fjob%3e%0d%0a%3c%2fidibu%3e
i've been able decode standard xml format here: http://coderstoolbox.net/string/#!encoding=url&action=decode&charset=us_ascii (paste info top box). below get:
xml_text=<?xml version='1.0' encoding='utf-8'?> <idibu> <method>add</method> <config> <show_durations>no</show_durations> <completionurl>email</completionurl> <advertcompletionemail>bob@bob.com</advertcompletionemail> <lockboards>yes</lockboards> <redirecturl>http://www.google.com </redirecturl> <validate_level>warning</validate_level> </config> <job> <title><![cdata[xml v 3 test, please ignore special £ $ & % @ ! ? . , = ) ( - : ; _ + ' ' ]]></title> <reference>abc123456789</reference> <description><![cdata[<b>special te £ $ & % @ ! ? . , = ) ( / - : ; _ + ' ' ' here euro basic te £ $ & % @ ! ? . , = ) ( / - : ; _ + ' ' ' special te £ $ & % @ ! ? . , = ) ( / - : ; _ + ' ' ' special te £ $ & % @ ! ? . , = ) ( / - : ; _ + ' ' ' basic te £ $ & % @ ! ? . , = ) ( / - : ; _ + ' ' ' ' , , · Ø ¨ ¦ ' : ' á º ¡ § é × ' : ' ' Ç ½ h ® ¬ á </b>]]> </description> <sender> <name>steve</name> <lastname>rogers</lastname> <email>test@mail.net</email> <company>one world market</company> <phone>44 (0) 111-1111111</phone> <www>http://uk.idibu.com </www> <country>uk</country> <postcode>020 1111 1111</postcode> </sender> <category id='21' /> <location id='8' /> <sublocation id='668' /> <jobtype id='2' /> <job_time>2</job_time> <startdate>2011-11-26</startdate> <duration>full time</duration> <salarymin>20000</salarymin> <salarymax>25000</salarymax> <salaryper value='annum' /> <salaryoverride>salary override test test</salaryoverride> <currency>gbp</currency> <publish>2011-11-26</publish> <posts> <board id='517'> <extrafield name='idibudts_cat'>3</extrafield> <duration days='7' /> </board> </posts> </job> </idibu>
in interest of simplicity, i'm setting api data in latter of 2 formats (standard xml). example, advertcompletionemail be:
echo "<advertcompletionemail>".$advert_email."</advertcompletionemail>";
the info has encode though in order send api once i'm done setting up. idibu documentation says needs encoded iso-8859-1 i'm assuming first block of code is. i've tried set whole xml data string ($str) , run:
echo "htmlentities($str)";
or
echo "htmlentities($str, ent_quote, iso-8859-1);
but neither works. tried utf8_decode($str) (and utf8_encode($str) though pretty sure wasn't right function) , didn't work. can me figure out how encode xml correct format? help!
i use iconv
can read in manual here: http://php.net/manual/en/book.iconv.php
if know sure it's utf-8 initially, can run function: http://www.php.net/manual/en/function.iconv.php
iconv("utf-8", "iso-8859-1", $xml)
and send api. it's strange api produce utf-8, require iso-8859-1. maybe i'm misunderstanding though.
Comments
Post a Comment