分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

php还原16进制特殊字符

发布时间:2023-09-06 02:06责任编辑:彭小芳关键词:暂无标签

特殊字符的16进制表:https://websitebuilders.com/tools/html-codes/ascii/

可以通过 hexdec()chr()方法来进行转换,

例子:

<?xml version=\x221.0\x22 encoding=\x22utf-8\x22?>\x0A<order id=\x22test\x22 affiliate=\x22main\x22 event_id=\x221\x22 ref=\x22TPCYA\x22 alias=\x22\x22/> 

其中 \x22 就是双引号 ",而 \x0A 就是换号 \n,通过一些方法转换后:

 ???$str = "<?xml version=\x221.0\x22 encoding=\x22utf-8\x22?>\x0A<order id=\x22test\x22 affiliate=\x22main\x22 event_id=\x221\x22 ref=\x22TPCYA\x22 alias=\x22\x22/>"; ???function hexdec_string($content) { ???????preg_replace_callback( ???????????"(\\\\x([0-9a-f]{2}))i", ???????????function($matches) {return chr(hexdec($matches[1]));}, ???????????// $string ???????????$content ???????); ?????????return $content; ???} ???echo htmlspecialchars(hexdec_string($str), ENT_QUOTES); //将 xml的内容作为纯文本输出

结果:

<?xml version="1.0" encoding="utf-8"?> <order id="test" affiliate="main" event_id="1" ref="TPCYA" alias=""/>

参考:https://stackoverflow.com/questions/12238657/decoding-javascript-escape-sequences-in-php-x27-x22-etc
           http://php.net/manual/en/function.preg-replace-callback.php

php还原16进制特殊字符

原文地址:https://www.cnblogs.com/tommy-huang/p/9382551.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved