I have been working on some QR codes, I need to pass an array to the QR with the data but it needs encoding. The data itself is a json_array which is used to generate a PDF.
If I use base64 encoding the QR code is stupidly large, and when using ascii85 it breaks the QR.
Can you let me know of any encoding praticies which would work in the url, the shorted the coding the betetr. qr_generator.php?data={encoded_json_array}
You can try this:
urlencode($string);
It encodes a string to be appended as an url parameter. So if you have an array, try:
urlencode(json_encode($array);
Related
I have string of URL with encoded google poly line. It has some time characters which are as same as PHP Escape Sequence (http://php.net/manual/en/regexp.reference.escape.php) such as \v and other too. When I call this URL to download image from remote server the URL string get's altered and does not work.
How to handle Escape Sequence to let php script download the image properly.
Below URL in DB:
http://maps.googleapis.com/maps/api/staticmap?size=275x270&sensor=true&markers=-31.95099,115.86053&markers=-31.952055,115.865051&path=weight:4%7Ccolor:0x0000FF%7Cenc:tl_bEi_dbUVol#gTug#aG_j#qe#_Le]_ZtO_i#tLsm#xd#sPdTu\sZeOq_#nZy_#wDsTah#_Dyl#cEg_#uImf#mKqU{WgJaEwd#mIs_#y[k]k^g[qi#GaUy\_Eqj#qi#aB{g#uJwi#uBe_#sYk^c_#ef#uOci#|A_h#_M}h#}Hcg#{Oi`#k]kIeh#tQsg#lKwa#fKs]~Fse#vi##v`#oIti#Dbc#fKza#aIrEe`#dh#hBvi#Q`[mOb^{Mpa#eYpP_k#Eah#e#an#xFwl#jBmn#Zaq#bAmp#nFap#gGon#_Iio#m#{p#nCgp#eE_p#~Hko#hBaq#jB}p#lYyXpe#mJv`#i\nc#}Wpg#_Obi#Dve#`S~d#bR~F~i#dVdd#|WpShJic#db#nKzGvo#ne#`Et^rXyE`o#mRhi#iCvp#oZrd#eJvo#lVdg#hKrn#cFzn#v[pMfh#\xCfYiX|Sf#~n#eNld#}V`]qNjZs`#hYwa#rQeXrUcNxf#}Ipn#lApp#rUzf#|h#rAvi#Ydi#mBvf#tQvb#rWbHzo#~Gjo#r]tb#vWlg#rXzd#eBbj#eTvi#uSzj#{Fdp#uJ~m#k\nc#i]fb#c]jb#o]~a#c^ra#ySfd#yQve#gZrUu\lLc`#x]aItm#fAxi#nHtl#pRjh#
Below URL out put from PHP:
http://maps.googleapis.com/maps/api/staticmap?size=275x270&sensor=true&markers=-31.95099,115.86053&markers=-31.952055,115.865051&path=weight:4%7Ccolor:0x0000FF%7Cenc:tl_bEi_dbUVol#gTug#aG_j#qe#_Le]_ZtO_i#tLsm#xd#sPdTu\sZeOq_#nZy_#wDsTah#_Dyl#cEg_#uImf#mKqU{WgJaEwd#mIs_#y[k]k^g[qi#GaUy\_Eqj#qi#aB{g#uJwi#uBe_#sYk^c_#ef#uOci#|A_h#_M}h#}Hcg#{Oi`#k]kIeh#tQsg#lKwa#fKs]~Fse#vi##v`#oIti#Dbc#fKza#aIrEe`#dh#hBvi#Q`[mOb^{Mpa#eYpP_k#Eah#e#an#xFwl#jBmn#Zaq#bAmp#nFap#gGon#_Iio#m#{p#nCgp#eE_p#~Hko#hBaq#jB}p#lYyXpe#mJv`#ic#}Wpg#_Obi#Dve#`S~d#bR~F~i#dVdd#|WpShJic#db#nKzGvo#ne#`Et^rXyE`o#mRhi#iCvp#oZrd#eJvo#lVdg#hKrn#cFzn#v[pMfh#%C3%8FYiX|Sf#~n#eNld#}V`]qNjZs`#hYwa#rQeXrUcNxf#}Ipn#lApp#rUzf#|h#rAvi#Ydi#mBvf#tQvb#rWbHzo#~Gjo#r]tb#vWlg#rXzd#eBbj#eTvi#uSzj#{Fdp#uJ~m#kc#i]fb#c]jb#o]~a#c^ra#ySfd#yQve#gZrUu\lLc`#x]aItm#fAxi#nHtl#pRjh#
The URL from DB show path properly, where as same url when out put from PHP does not show path at all. Also the length of url gets reduced when output from PHP.
thanks
Waqas
You could use good old base64encode to encode the url and before you store in the database, if you have access to that code. Uses 33% more space, but helps with escape headaches. PHP - Base64 Encode
I am trying to call the USPS API that takes in the zip code and returns XML containing the City Name of the given zip code.
Here is the URL they require:
http://production.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup
&XML=<CityStateLookupRequest USERID="xxxxxxx"><ZipCode ID= "0">
<Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>
In my PHP file, when I echo out the above URL, this is what I get:
http://production.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=90007
All the XML part of the URL is missing. I need to get curl data from the URL.
Anyone know what I could be missing?
Anyone know what I could be missing?
Probably. Maybe, yes. What you describe in your posting sounds like an encoding problem. So you are missing the right encoding.
As you are talking about an URL that is likely URL encoding. Some characters - like space - have a special meaning inside an URL so you can not just use any character as you like, but you need to encode all characters properly.
The exact description how you need to formulate an URL incl. the exact description how URL encoding works is outlined in 2. Characters in the internet standard RFC3986.
PHP functions related to URL encoding are urlencode() and rawurlencode and more likely useful in your case http_build_query().
http://php.net/manual/en/function.urlencode.php should get you started if you want to encode the xml into the URL.
I have a big problem : I don't have the same result if I do base64_decode($string); in php or if I do Base64.decode(string); in android.
Example :
with this string : WWhiZWWSZpNlaGSTnpljZQ==
In php, result is Yhbee’f“ehd“ž™ce .
In android, the result is Yhbee�f�ehd���ce
I think there is an encoding problem, but I don't know where, the output of my PHP server is ISO-8859-1, I don't find how to tell to Base64.decode to use this type of encoding.
Can you help me please. Thx for answers.
PS : I can't touch the PHP script.
I think this will help you, Don't use .toString() use this instead
var str = "WWhiZWWSZpNlaGSTnpljZQ=="
var decoded = String(Base64.decode(str, Base64.NO_WRAP))
I know this to late to answer :-D
You should try this:
Base64.decode(content.getBytes("ISO-8859-1"), Base64.DEFAULT);
By this You convert the input String content to ISO-8859-1 encoded byte stream that will be decoded from base64.
I think the decode is fine, but Android isn't applying the right encoding (probably utf-8).
Does this content appear on an HTML page? If so, are you properly enforcing the ISO-8859-1 encoding?
Alternatively, you could also switch to UTF-8.
I have a VB6 application that is creating a JSON string and posting it to a website (PHP5). It may look like this:
data=thisisthejsonstringitcontainsthe£hmtlcharacter&code=123&api_key=321
This is an issue because the £ is thought to be the start of a new variable so the json string is being cut.
Does this need to be encoded somehow at the VB source? Or can I do something with this when it arrives at the website? If it needs encoded by VB can anyone suggest a suitable function?
I'm using the application/x-www-form-urlencoded content type when posting.
This might seem far fetched, but have you tried sending £ urlencoded beforehand? being %26pound
If you send url arguments to a webserver, you'll need to urlencode them. That's true for all arguments in formats that don't escape and can contain problematic characters themselves, which includes JSON.
I am pulling data from the Facebook graph which has characters encoded like so: \u2014 and \u2014
Is there a function to convert those characters into HTML? i.e \u2014 -> —
If you have some further reading on these character codes), or suggested reading about unicode in general I would appreciate it. This is so confusing to me. I don't know what to call these codes... I guess unicode, but unicode seems to mean a whole lot of things.
that's not entirely true bobince.
How do you handle json containing spanish accents?
there are 2 problems.
I make FB.api(url, function(response)
... var s=JSON.stringify(response);
and pass it to a php script via $.post
First I get a truncated string. I need escape(JSON.stringify(response))
Then I get a full json encoded string with spanish accents.
As a test, I place it in a text file I load with file_get_contents and apply php json_decode and get nothing.
You first need utf8_encode.
And then you get awaiting object of your desire.
After a full day of test and google without any result when decoding unicode properly, I found your post.
So many thanks to you.
Someone asked me to solve the problem of Arabic texts from the Facebook JSON archive, maybe this code helps someone who searches for reading Arabic texts from Facebook (or instagram) JSON:
$str = '\u00d8\u00ae\u00d9\u0084\u00d8\u00b5';
function decode_encoded_utf8($string){
return preg_replace_callback('#\\\\u([0-9a-f]{4})#ism', function($matches) { return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE"); }, $string);
}
echo iconv("UTF-8", "ISO-8859-1//TRANSLIT", decode_encoded_utf8($str));
Facebook Graph API returns JSON objects. Use json_decode() to read them into PHP and you do not have to worry about handling string literal escapes like \uNNNN. Don't try to decode JSON/JavaScript string literals by yourself, or extract chosen properties using regex.
Having read the string value, you'll have a UTF-8-encoded string. If your target HTML is also UTF-8-encoded, you don't need to replace — (U+2014) with any entity reference. Just use htmlspecialchars() on the string when outputting it, so that any < or & characters in the string are properly encoded.
If you do for some reason need to produce ASCII-safe HTML, use htmlentities() with the charset arg set to 'utf-8'.