![](/img/trans.png)
[英]hex codec / base64 encoding in PHP (converting from python)
[英]PHP Hex Code read as Hex strings when encoding to base64
我有一組這種格式的十六進制代碼
FF8FFE00+++++
上面的例子只是一個字符串,+ 代表超過 60k 長的十六進制代碼的 rest(在占用您的瀏覽器時沒有用處)。 格式看起來完全一樣。 所以讓我們說
$a = 'FFD8FF++++ string';
echo base64_encode($a);
打印上述內容時,它將十六進制代碼作為字符串並從字符串中生成 base64 而不是 hexdec
看了一遍,但似乎有兩種轉換使十六進制代碼也得到十六進制編碼。
在 NPP+ 中,我將字符串轉換為 ASCII,然后在 base64 中編碼,結果是預期的(我可以用於圖像的 base64)。
知道如何告訴 php 該字符串實際上是十六進制節點,而不是字符串嗎?
使用hex2bin ,您可以將包含十六進制的字符串轉換為二進制數據(在 PHP 中存儲為字符串)。 之后將二進制字符串編碼為 base64 格式。
$hex = 'FFD8FF'; // and much more hex values as string as in your example
$bin = hex2bin($hex); // convert the hex values to binary data stored as a PHP string
$b64 = base64_encode($bin); // this contains the base64 representation of the binary data
字符串(4)“/9j/”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.