{"id":223,"date":"2022-08-30T14:57:46","date_gmt":"2022-08-30T14:57:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/08\/31\/problem-about-unpack-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:57:46","modified_gmt":"2022-08-30T14:57:46","slug":"problem-about-unpack-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-unpack-record-and-share-programming-errors\/","title":{"rendered":"problem about unpack-Record and share programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aff833a89697f43d13f8a4fe6b5e7863?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTrav McKinney<br \/>\nruby-on-rails base64 activesupport unpack<br \/>\nIn one of my Rails controllers I am trying to take a Base64 encoded string, decode it and write it to a file (.png). Here is my code:def create_character@character = Character.new(params[:char<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/13944a2e637dddd468be2ce184a8bab5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBas Jansen<br \/>\nphp arrays decode unpack uncompress<br \/>\nI have a binary data string that i uncompress and unpack into an array using php with the following code (complete code for this php page is included at the bottom of this question):while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$glycopeptide[$hits] = $row[1];echo $row[4];\/\/ $row[4] contains the binaryString$mz = base64_decode($row[4]);$unc_mz = gzuncompress($mz);$max = strlen($unc_mz);$counter = 0;for ($i = 0; $i &lt; $max; $i = $i+4) {$temp = substr($unc_mz,$i,4);$temp = unpack(&#8220;f&#8221;,$temp);$mz_array[$counter] = $temp[1];$counter++;}$hits++; }I find that both the mz_array (the above code, X-coords) has 9 undefined values (all at the end) but that the int_array (similar code, Y-coords) also has 9 undefined values (distributed throughout the whole array (not grouped or at the beginning\/end).Here is an example of a small testing chunk that I added to my page:Test code:for ($i = 0; $i &lt; $counter; $i++) {echo $i;echo &#8221; &#8211; &#8220;;echo $mz_array[$i];echo &#8221; &#8211; &#8220;;echo $int_array[$i];echo &#8220;<br \/>\n&#8220;; } A &#8220;selection&#8221; of the output (Note the missing values):671 &#8211; 274.20001220703 &#8211; 429 672 &#8211; 274.39999389648 &#8211; 673 &#8211; 274.60000610352 &#8211; 1098 &#8212; skipping a few lines &#8212; 10299 &#8211; 2199.8000488281 &#8211; 0 10300 &#8211; 2200 &#8211; 0 10301 &#8211; &#8211; 0 10302 &#8211; &#8211; 0The weirdest part is that if i manually enter the strings in the complete\/original code (see bottom of page) I get the undefined values while if I manually enter the string that is returned by doing &#8220;echo $row[4]&#8221; (contains the binaryString) in the following code it yields no undefined values. Does anyone have any suggestions or idea&#8217;s why this might occur?PS: Can someone add the tag gzuncompress? (I don&#8217;t have the reputation for it).EDIT 1I have included an example binaryString (WARNING: Huge!)Y-Coords (retrieved by the commented echo $row[4] in the code):eJztXQuQFMUZblQEQfEQUQSJYwRBSuLG+AAFHdmeRYOPS2lRgEgNvgpLhUuQkooYB5GXBLIaHwRQRwMpCqOuiciJhU4KjUoMnm98r2KUaKkXreBpSCXf3z3Lzu7Na3fn9nZhvqop2N2enu6\/\/\/7fPcdYjBgxYsSIESNGjBhVgvFGkqmLOWPjk77tlNs5a35AY9kdnBlPo+3GMZ5tm87VmDULfXL\/PnOwzkGfP0P7RLj2MUrAaNB0l2OtJuDzVu+188XJnKmnYZ0a5DpZE7Fu3TVm\/BOft5TZZ4yqwvwf1u+ne89ea7wM\/Pke5vvI3jHfGGVA56xxEnTWKeCT\/h588i5k3cEp1vyuxtQN+H\/an5+ya9GuBf2t6zi+s2ZAHh\/KC+V7BTDXoK\/15Y03uxD3zo1urmoKND4efXb17tPqgTZz0OYy\/+eaB2uMHYP1UKOjVc1gDuy30TUuz3fWP82NJuy1nZyZx4GXDgO9M\/acXgPd9w+mvXFrx66P+TLGNBnXBbXBB4tWwldYhvFcGmI8GbRJ1xGPhFjvPQXqvljDbZjv6jpan1pHfxcfjHyqm0Hra8vnraa+sGF68prmz4aeGtM3Y4wr3fd8I35nrxfZTU\/g88YK\/NbORAJ6owvG31Y49mwT\/JJFXPrjYQBZSrGaAj97UMTrfFYJ4wkD9GUYtcuLBHU7Z\/rzoO3dtT1OgQ0Y42neNqyFuSjrOcuamNMo7KPzecHvR45MsYtwKZfAFh7GBS9lv0LbH+BzH+67v7KvcBEDdNrarV0hb77Ddy9VWT9AFmRfwJqtqR+9pF8MGq\/iwl7PId1bY62DQcMGB+0hF5W1th8WIO\/a7a0TsN+maDK+M9qdnynWao3H76fVAb87oN8K2\/s3XNDKfE5jzc0aW7sRNuYhkKM7bFpNt23g\/XhhfBp6RtDKoW\/UXmjzkaPNefg8j2Jj9UWXmgN4z7gnT0N1IuTRZ5yle4<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-08-31 04:41:18. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Trav McKinney ruby-on-rails base64 activesupport unpack In one of my Rails controllers I am trying to take a Base64 encoded string, decode it and write it to a file (.png). Here is my code:def create_character@character = Character.new(params[:char Bas Jansen php arrays decode unpack uncompress I have a binary data string that i uncompress and unpack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}