源码:特别适用于微信支付中通知微信支付网关
function array2xml($arr, $level = 1) {
$s = $level == 1 ? "<xml>" : '';
foreach ($arr as $tagname => $value) {
//元素为数组或者不为数组的处理
if (!is_array($value)) {
$s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : '') . $value . (!is_numeric($value) ? ']]>' : '') . "</{$tagname}>";
} else {
$s .= "<{$tagname}>" . array2xml($value, $level + 1) . "</{$tagname}>";
}
}
//过滤不合法的字符串
$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
return $level == 1 ? $s . "</xml>" : $s;
}
//微信支付通知后告诉微信网关,我收到了!
$data=array(
'return_code'=>'SUCCESS',
'return_msg' =>'OK',
);
$xmlstr=array2xml($data); 面试中PHP面试官会问调用一个不存在的方法,如何知道是哪个文件哪行调用的?假设方法是getWorkLoad()回答1:开启PHP错误输出,PHP会输出Fatal error: Call to undefined function getWorkLoad() in D:\wwwroot\thinkpa...
在编写多进程的实例中我在每个进程中使用如下代码://调用等待信号的处理器 while (true) { pcntl_signal_dispatch(); }开启5个进程,cpu直接100%修正之后的代码://调用等待信号的处理器 while&...
<?php $member = new class { public function getInfo() { ...
当我想在一个进程中监听kill 和 kill -9命令报了这个错误。//监听kill pcntl_signal(SIGTERM, function () { posix_kill(0, SIGTERM); });...
在使用ftok生成ipc进程通信key尝试将第二个参数项目标识符传入字符串报错:PHP Warning: ftok(): Project identifier is invalid,查阅资料发现第二个字符串只能是1个字符串,长度为1....
自己的composer已经发布到packagist,但是无法使用composer require easy-task/easy-task来安装,只能在配置文件使用如下方式安装:"require": { "easy...