Php base base64 encode and decode not working correctly

java rocks

I want to encode and decode in php using base64, but the encode and decode function does not give me correct output. I am using code from online php functions.

I encode this string

"best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي"

and get the output:

"YmVzdCBhcmFiaWMgc29uZ3MgbG92ZXMgMjAxMyBub25zdG9wINij2YHYttmEINmF2YYg2KfZhNij2LrYp9mG2Yog2KfZhNit2Kgg2KfZhNis2K/ZitivINmD2YTZhdin2Kog2KfZhNi52LHYqNmK"

When I use this php code it does not give a correct encode and decode string:

    $str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي';
    $decodestr = base64_decode($str);

    echo 'decode = '.$decodestr

    $encodestr = base64_encode($decodestr );

    echo '<br>';
    echo 'encode = '.$encodestr;



    i got this output :

decode = më-j¶›‰Ë(ž%¢÷¬ÛMwž‰ì¶Š

encode = bestarabicsongsloves2013nonstoo=

Can any one help me with how I can get correct encode and decode string using base64 encode and decode function in php?

StackB00m

the function base64_decode only decodes already base64encoded chunk . In your code you are trying to base64decode a plain text which is causing issues.

<?php $str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي'; $encodestr = base64_encode($str); echo 'Base64 encoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$encodestr; $decodestr=base64_decode($encodestr); echo '<br><br><br>'; echo 'Base64 decoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$decodestr; ?>

Try this code it works find for me !

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

BASE64 Encode and Decode is not working

From Dev

Why decode using base64 not working correctly in C#

From Dev

base64 decode not working

From Java

Base64 Java encode and decode a string

From Dev

base64 encode in python, decode in javascript

From Dev

base64 decode/encode inconsistency

From Dev

Python Decode base64 to picture not working

From Dev

PHP base64 encode a pdf file

From Dev

Decode base64 string - php

From Dev

Base64 decode image PHP

From Dev

base64 Decode into PHP Array

From Dev

base64 Decode into PHP Array

From Dev

BASE64 decode and ungzip data in PHP

From Java

How do I encode and decode a base64 string?

From Dev

base64 encode, decode to, from files in chunks with python 2.7

From Java

How to Convert Pdf to base64 and Encode / Decode

From Dev

Unable to make Guava base64 encode/decode work

From Dev

Encode UIImage in iOS7 and Decode it in Java (Base64)

From Dev

Base64 decode encode, getting different data

From Dev

Apache codec base64 encode/decode - not getting expected result

From Dev

Base64 encode/decode without padding on golang ( appengine )

From Dev

How to Convert Pdf to base64 and Encode / Decode

From Dev

Extra new lines on base64 encode/decode in Python?

From Dev

Encode UIImage in iOS7 and Decode it in Java (Base64)

From Dev

Different output after decode and encode data (base64)

From Dev

Base64: how to encode / decode the entire HTML code of a page

From Dev

Base64 Encode/Decode in Nativescript With Angular 2

From Dev

Encode base64 in Python and decode in C#

From Dev

Encode base64 and Decode base64 using delphi 2007