- print_r: documentation ( source)
- preg_match_all: documentation ( source)
- preg_quote: documentation ( source)
<?php
$str = '<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<sessionId>1073741(eA14011269142xC071</sessionId>
<device_id></device_id>
<sessionTime>1429457223</sessionTime>
<trans_time>1429457223</trans_time>
<mpb>1000</mpb>
<user_id>1335</user_id>
<user_name>ltt1835</user_name>
<alias>Lotto8 陈</alias>
<display_user_points>3999</display_user_points>
<message>剩余积分不足, 请充值后再继续。</message>
<transfer_points>0</transfer_points>
<user_points>3999</user_points>
<fund_status>100</fund_status>
<Jackpot>
<jackpot_amount>1582668</jackpot_amount>
<jackpot_ceiling>10000</jackpot_ceiling>
<jackpot_preserved>800000</jackpot_preserved>
<message_front>总奖池目前已经高达</message_front>
<message_mid>分,大奖随时开出,多玩多赢。</message_mid>
<message_end></message_end>
<message_top>两次开奖,奖上有奖,喜上加喜</message_top>
</Jackpot>
<card_number>1073741835</card_number>
<status>1</status>
</DATA>';
print_r( get_tag("status", 1, $str));
function get_tag( $attr, $value, $xml, $tag=null ) {
if( is_null($tag) )
$tag = '\w+';
else
$tag = preg_quote($tag);
$attr = preg_quote($attr);
$value = preg_quote($value);
$tag_regex = "/<(".$tag.")[^>]*$attr\s*=\s*".
"(['\"])$value\\2[^>]*>(.*?)<\/\\1>/";
preg_match_all($tag_regex,
$xml,
$matches,
PREG_PATTERN_ORDER);
return $matches[3];
}
?>