php - Differences in base64_encode() -


i trying write php script takes in csv file , creates ldifde file importing students ad.

i have working password.

the problem seems base64_encode() in php.

echo $password = '"password1"'; echo "<br />"; echo $testpass = base64_decode("igbqageacwbzahcabwbyagqamqaiaa=="); echo "<br />"; echo base64_encode($password); echo "<br />"; echo "igbqageacwbzahcabwbyagqamqaiaa=="; echo "<br />"; echo base64_encode($testpass); 

the output is:

"password1" "password1" ilbhc3n3b3jkmsi= igbqageacwbzahcabwbyagqamqaiaa== igbqageacwbzahcabwbyagqamqaiaa== 

i can't find differnece between "password1"'s. have idea doing wrong here? once can initial , encoded $password match encoded $testpass, should able working right.

i'm going refer 2 base64 encoded strings "the short string" , "the long string".

the long string seems short string encoded utf16 little endian (or ucs-2le). check out hexdump of decode of long string:

          00 01 02 03 04 05 06 07 - 08 09 0a 0b 0c 0d 0e 0f  0123456789abcdef  00000000  22 00 50 00 61 00 73 00 - 73 00 77 00 6f 00 72 00  ".p.a.s.s.w.o.r. 00000010  64 00 31 00 22 00                                  d.1.". 

as can see, there null byte following each valid ascii byte, differences coming from. question is, want long string or short string? either way, check out mb_convert_encoding() in php manual you're going.

the encoding long string "ucs-2le"; encoding short string "iso-8859-1" or "cp1252". put these in "from" , "to" arguments according 1 trying produce.

edit - required calls

i posted in comments, ease of reference, i'm including here. in order long string, call mb_convert_encoding() 'ucs-2le' second argument. example:

$password = '"password1"'; echo base64_encode(mb_convert_encoding($password, 'ucs-2le')); 

produces:

igbqageacwbzahcabwbyagqamqaiaa== 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -