001源码:
/*
* $xml_str是xml字符串
*/
function xmltoarray($xml_str)
{
//禁止XML实体扩展攻击
libxml_disable_entity_loader(true);
//拒绝包含HTML结构(避免出现html解析攻击);
if (preg_match('/(\<\!DOCTYPE|\<\!ENTITY)/i', $xml_str)) {
return false;
}
//返回的数组对象
$result=array();
//LIBXML_NOCDATA - 将 CDATA 设置为文本节点,微信支付的xml,可以自己定义
$xmlobj=simplexml_load_string($xml_str, 'SimpleXMLElement',LIBXML_NOCDATA);
//是否是SimpleXMLElement对象
if($xmlobj instanceof SimpleXMLElement)
{
$result=json_decode(json_encode($xmlobj),true);
}
return $result;
}
$xmlfile=file_get_contents('1.txt');
$xmlarray=xmltoarray($xmlfile);002.原xml字符串:(微信支付通知的xml字符串)
<xml> <appid><![CDATA[wx2421b1c4370ec43b]]></appid> <attach><![CDATA[支付测试]]></attach> <bank_type><![CDATA[CFT]]></bank_type> <fee_type><![CDATA[CNY]]></fee_type> <is_subscribe><![CDATA[Y]]></is_subscribe> <mch_id><![CDATA[10000100]]></mch_id> <nonce_str><![CDATA[5d2b6c2a8db53831f7eda20af46e531c]]></nonce_str> <openid><![CDATA[oUpF8uMEb4qRXf22hE3X68TekukE]]></openid> <out_trade_no><![CDATA[1409811653]]></out_trade_no> <result_code><![CDATA[SUCCESS]]></result_code> <return_code><![CDATA[SUCCESS]]></return_code> <sign><![CDATA[B552ED6B279343CB493C5DD0D78AB241]]></sign> <sub_mch_id><![CDATA[10000100]]></sub_mch_id> <time_end><![CDATA[20140903131540]]></time_end> <total_fee>1</total_fee> <coupon_fee><![CDATA[10]]></coupon_fee> <coupon_count><![CDATA[1]]></coupon_count> <coupon_type><![CDATA[CASH]]></coupon_type> <coupon_id><![CDATA[10000]]></coupon_id> <coupon_fee><![CDATA[100]]></coupon_fee> <trade_type><![CDATA[JSAPI]]></trade_type> <transaction_id><![CDATA[1004400740201409030005092168]]></transaction_id> </xml>
<?php echo similar_text("Hello World","Hello Shanghai"); ?> 2.计算两个字符串的相似度,并返回百分比 <?php similar_text("...
<?php function go($str) { echo'I\'m '.$str; } $goto='go'; $goto('gaojiufeng'...
首先下载wkhtmltox-0.12.4_linux-generic-amd64.tar.xz (不要下载RPM包,依赖太多,需要x-server支持),并解压,执行测试运行正常tar wkhtmltox-0.12.4_linux-generic-amd64.tar.xzcd...
通过http推送消息给socket,socket服务再向客户端推送<?php /* * Socket推送 * 请用守护进程方式启动php msgservice.php & (socket只...
PHP不像net支持多继承,自身只支持单继承,为了解决这个问题,php出了Trait这个特性,减少单继承语言的限制。并且能让代码复用率更高。说白了就是一个对象的属性和方法扩展工具一样。例如:trait exts { public f...
最近在编写windows php多线程的东西,从官网下载了PHP的线程安全版,尝试开启curl扩展extension=php_curl.dllphp -m 却提示 PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl...