用于多个术语的php正则表达式

用于多个术语的php正则表达式,php,regex,Php,Regex,我有这个字符串(来自GoDaddy清单xml),我希望将每个值分配给一个变量: 拍卖类型:报价,拍卖结束时间:2012年12月8日凌晨5:57(PDT),价格:$4000,出价数量:0,域名期限:0,描述:1234我宣布一场拇指大战,1234ideclareathumbwar.com,流量:0,估价:$0,IsAdult:true 我的问题是,如何使用regexp实现这一点 我已经试过了: $re = "Auction Type: (.+?), "; $re .= "Auction End T

我有这个字符串(来自GoDaddy清单xml),我希望将每个值分配给一个变量:

拍卖类型:报价,拍卖结束时间:2012年12月8日凌晨5:57(PDT),价格:$4000,出价数量:0,域名期限:0,描述:1234我宣布一场拇指大战,1234ideclareathumbwar.com,流量:0,估价:$0,IsAdult:true

我的问题是,如何使用regexp实现这一点

我已经试过了:

$re  = "Auction Type: (.+?), ";
$re .= "Auction End Time: (.+?) \(.+?\), ";
$re .= "Price: .(.+?), ";
$re .= "Number of Bids: (.+?), ";
$re .= "Domain Age: (.+?), ";
$re .= "Description: (.*?), ";
$re .= "Traffic: (\d*)(.*?)";
$re .= "Valuation: (.+?), ";
$re .= "IsAdult: (.+?), ";

if(preg_match("~".$re."~is",$description,$m)){
    $record = Array('auctiontype' => trim($m[1]),
        'endtime'     => strtotime($m[2]),
        'price'       => str2float($m[3]),
        'bids'        => trim($m[4]),
        'age'         => trim($m[5]),
        'description' => addslashes(trim($m[6])),
        'traffic'     => trim($m[7]),
        'valuation'   => trim($m[8]),
        'isadult'     => trim($m[9])
    );
}
但它不起作用。我可以寻求帮助吗

谢谢大家!

$re  = "Auction Type: (.+?), ";
$re .= "Auction End Time: (.+?) \(.+?\), ";
$re .= "Price: .(.+?), ";
$re .= "Number of Bids: (.+?), ";
$re .= "Domain Age: (.+?), ";
$re .= "Description: (.*?), ";
$re .= "Traffic: (\d*)(.*?), ";
$re .= "Valuation: (.+?), ";
$re .= "IsAdult: (.+?)$";

你忘了一个
,我也将
更改为
$
,对于$re的最后一部分,正如Leon Kramer所说,你必须将re的最后一个元素更改为:

$re .= "IsAdult: (.+)$";
还有,
$re.=“流量:(\d*)(.*)”包含两个组(即$m[7]和$m[8]),因此更改

$record = Array('auctiontype' => trim($m[1]),
    'endtime'     => strtotime($m[2]),
    'price'       => str2float($m[3]),
    'bids'        => trim($m[4]),
    'age'         => trim($m[5]),
    'description' => addslashes(trim($m[6])),
    'traffic'     => trim($m[7]),
    'valuation'   => trim($m[8]),
    'isadult'     => trim($m[9])
);


我不知道您想用给定示例中为空的
$m[8]
做什么。

匹配后是否打印了结果数组?哇!就在那里!非常感谢D
$record = Array('auctiontype' => trim($m[1]),
    'endtime'     => strtotime($m[2]),
    'price'       => str2float($m[3]),
    'bids'        => trim($m[4]),
    'age'         => trim($m[5]),
    'description' => addslashes(trim($m[6])),
    'traffic'     => trim($m[7]),
    'valuation'   => trim($m[9]),   // here
    'isadult'     => trim($m[10])   // and here
);