How to convert php files to hexadecimal: 1. Create a PHP sample file; 2. Convert the file content to hexadecimal output through the "function fileToHex($file){...}" method That’s it.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
How to convert php files to hexadecimal?
Example of method of converting files to hexadecimal in php
The code is as follows:
<?php /** * php 文件与16进制相互转换 * Date: 2017-01-14 * Author: fdipzone * Ver: 1.0 * * Func * fileToHex 文件转16进制 * hexToFile 16进制转为文件 */ /** * 将文件内容转为16进制输出 * @param String $file 文件路径 * @return String */ function fileToHex($file){ if(file_exists($file)){ $data = file_get_contents($file); return bin2hex($data); } return ''; } /** * 将16进制内容转为文件 * @param String $hexstr 16进制内容 * @param String $file 保存的文件路径 */ function hexToFile($hexstr, $file){ if($hexstr){ $data = pack('H*', $hexstr); file_put_contents($file, $data, true); } } // 演示 $file = 'test.doc'; // 文件转16进制 $hexstr = fileToHex($file); echo '文件转16进制<br>'; echo $hexstr.'<br><br>'; // 16进制转文件 $newfile = 'new.doc'; hexToFile($hexstr, $newfile); echo '16进制转文件<br>'; var_dump(file_exists($newfile)); ?>
Output:
文件转16进制 efbbbf3130e4b8aae4bfafe58da7e69291e28094e280943235e4b8aae4bbb0e58da7e8b5b7... 16进制转文件 boolean true
Recommended study:《 PHP video tutorial》
The above is the detailed content of How to convert php files to hexadecimal. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
