1

I am facing the following issue. There is an array contaning several strings. We'd like to append eachother together. The implode function seems so be the solution.

Here is the detailed data in the array:

0   -----BEGIN ENCRYPTED PRIVATE KEY-----\n 
1   MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIR9as3yoyQisCAggA\n  
2   MBQGCCqGSIb3DQMHBAjr2e4eD62llQSCAoDOrZP66BNtAZNBhoyRRzPOYOXhBuG4\n  
3   ah/505qbWe+SlgSnp1GYS+mgrbMc6OCv6O+gUBMzX/oVHhZeE08CQI/a5V4nDyns\n  
4   I+v8c9nYdEPYVSpPQHSwYeA8zQErqBPkzUpG2PCrCSMixC0hfUK+2z8Q1C6rTMnQ\n  
5   JYQk7JPo+nNug+xEEETWt02g9vypo2F8NKcQQ3oSKdxmuGYzbIRFMMF9CYb5ruB2\n  
6   QcWGbi1Bb+28EozEv8sABOGfOF7SVC1o4IY/n0e/QPL67uPUmdJEi5PfDkoQpmYq\n  
7   G9wBEHpMr/XtQcYhHILFWI5a8bPGb/IOuNXUrYURVG6eIU/UJpyJAgoD7lHzKvB5\n  
8   n8Sya94Mbdt21oPRJOv8zcgnd4L9wcY9FK3kkWoxM1oFw4Y+lxrcIBKzy2dZF5uc\n  
9   8kiCM/25jbUCvKfvuEa8SiAZj7v9BudNwAspqFae/XMMoj5RGzXElEN/A28Je+vZ\n  
10  mfMiA2nDtsBXfxDtdxnRchAG2c35wau/HxLO427CcI1CoRyDtUnNPEUmsgIY6cMW\n  
11  tcG4mycApdfnSIwgvWpsj/hyEOICDR/q7+APu32Dc4jf6/r6gV0ItgdiNU4wXaNy\n  
12  HPjreeL6g/ndfd6LwIyIBdJp4jhvcUWgEGDXUBfkhQJVx+8xZJAYw+sfYXQiFuZd\n  
13  fyYv0pOR8F7FIdNC32zIFQpYdZ/SPROTY0FSNGlCUc1L0HX44E9T8bG9F+Lm9jpD\n  
14  1ME4SG+XkF9QBAuDGTIVk/qQCK1fIlyrO4t/6hCu9z1+7ZeXxqi2D/D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Tgs\nW2F8oaOxOv5q5d9X/Bneb+8FpNWdACvmW9NtVLaBjI0VO3Ew+xHj8tyd\n-----END ENCRYPTED PRIVATE KEY-----

The code I have looks something like this.

$arr = array();
...
$arr = $dataweloaded;
$string = implode($arr);

Now the really interesting thing..

My real output is not as described above. It contains just 1024 bytes.

-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIR9as3yoyQisCAggA\nMBQGCCqGSIb3DQMHBAjr2e4eD62llQSCAoDOrZP66BNtAZNBhoyRRzPOYOXhBuG4\nah/505qbWe+SlgSnp1GYS+mgrbMc6OCv6O+gUBMzX/oVHhZeE08CQI/a5V4nDyns\nI+v8c9nYdEPYVSpPQHSwYeA8zQErqBPkzUpG2PCrCSMixC0hfUK+2z8Q1C6rTMnQ\nJYQk7JPo+nNug+xEEETWt02g9vypo2F8NKcQQ3oSKdxmuGYzbIRFMMF9CYb5ruB2\nQcWGbi1Bb+28EozEv8sABOGfOF7SVC1o4IY/n0e/QPL67uPUmdJEi5PfDkoQpmYq\nG9wBEHpMr/XtQcYhHILFWI5a8bPGb/IOuNXUrYURVG6eIU/UJpyJAgoD7lHzKvB5\nn8Sya94Mbdt21oPRJOv8zcgnd4L9wcY9FK3kkWoxM1oFw4Y+lxrcIBKzy2dZF5uc\n8kiCM/25jbUCvKfvuEa8SiAZj7v9BudNwAspqFae/XMMoj5RGzXElEN/A28Je+vZ\nmfMiA2nDtsBXfxDtdxnRchAG2c35wau/HxLO427CcI1CoRyDtUnNPEUmsgIY6cMW\ntcG4mycApdfnSIwgvWpsj/hyEOICDR/q7+APu32Dc4jf6/r6gV0ItgdiNU4wXaNy\nHPjreeL6g/ndfd6LwIyIBdJp4jhvcUWgEGDXUBfkhQJVx+8xZJAYw+sfYXQiFuZd\nfyYv0pOR8F7FIdNC32zIFQpYdZ/SPROTY0FSNGlCUc1L0HX44E9T8bG9F+Lm9jpD\n1ME4SG+XkF9QBAuDGTIVk/qQCK1fIlyrO4t/6hCu9z1+7ZeXxqi2D/D8LOItzTgs\nW2F8oaOxOv5q5d9X/Bneb+8FpNWdACvmW9NtVLaBjI0VO3Ew+xHj8tyd\n-----END ENCRYPTED     

If you compare those string, you should realise that a few bytes are missing! The current output should have been appended with PRIVATE KEY-----\n hence this was part in the last element of the array, which would result in -----END ENCRYPTED PRIVATE KEY-----.

I actually just achieve -----END ENCRYPTED .

I thought about heap memory limitations. php.ini sais 256Mb are reserved. I also read that variables can get up to 2Gb large. So this should not be the problem in here.

implode() should also be fine, because of the fact that other funcitons like file_get_contents() do also return the identical wrong result.

Reading the code like by line like the in the following:

function readline($file){
    $string = null;
    $handle = fopen($file, "r");
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
            $string .= $line;
        }
        fclose($handle);
    }
return $string;
}

I kept searching for the mistake a long time. Tracing the calls inside of a debugger made it even possible to recognize a fix size of 1024 bytes in every case, no mattre what method i used.

Have you ever experienced such an abnormal behavior? I hope this is not too easy and I am just missing something important.

The resulting string should contain the exact same data as in the array elements.

3
  • Please be patient if the title may not be the main question. I can not think of a better one at the moment. Commented Jul 5, 2015 at 18:29
  • 1
    I can't reproduce your result :( - eval.in/393023 Commented Jul 5, 2015 at 18:42
  • Oh it really seems that the result was all over the time fine. The debug interface of Eclipse or XDebug is not working well. Thank you very much, you saved a lot of time =) Commented Jul 5, 2015 at 18:50

1 Answer 1

2

There seems to be a serious problem with the debugger utility I used. Here an image that shows the phenomen. I highly assume that only 1024 bytes will be presented in the variable content viewer in the debug mode. The code is well, php isn't fault =)

There was no real problem in before.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.