有个jt.xml文件,utf-8格式,内容如下<root>
<SecondHouse id="217045" userid="jtzy" password="123456" del="0">
<House>3-2-2</House>
<AddDate>2010-11-2 16:35:08</AddDate>
</SecondHouse>
<SecondHouse id="217042" userid="jtzy" password="123456" del="0">
<House>3-2-1</House>
<AddDate>2010-11-2 16:30:56</AddDate>
</SecondHouse>
<SecondHouse id="217041" userid="jtzy" password="123456" del="0">
<House>2-2-1</House>
<AddDate>2010-11-2 16:19:06</AddDate>
</SecondHouse>
</root>现需用php代码把此页面中的 House AddDate 这二个字段内容放入二维数组中,如何实现呀,thanks
<SecondHouse id="217045" userid="jtzy" password="123456" del="0">
<House>3-2-2</House>
<AddDate>2010-11-2 16:35:08</AddDate>
</SecondHouse>
<SecondHouse id="217042" userid="jtzy" password="123456" del="0">
<House>3-2-1</House>
<AddDate>2010-11-2 16:30:56</AddDate>
</SecondHouse>
<SecondHouse id="217041" userid="jtzy" password="123456" del="0">
<House>2-2-1</House>
<AddDate>2010-11-2 16:19:06</AddDate>
</SecondHouse>
</root>现需用php代码把此页面中的 House AddDate 这二个字段内容放入二维数组中,如何实现呀,thanks
<?php
$xml = simplexml_load_file('jt.xml');//文件方式
foreach($xml->SecondHouse as $SecondHouse){
$House[] = (array)$SecondHouse->House;
$AddDate[] = (array)$SecondHouse->AddDate;
}
?>$House[0]和$AddDate[0]就是你要的结果!
<?php
$xml = file_get_contents('jt.xml');
preg_match_all("/.*\<House\>\d+\-\d+\-\d+\<\/House\>.*/",$xml,$House);
print_r($House[0]);
?>AddDate可参考House
16楼的可运行,可我想把 hosue 之间的不用 d+ d+ 的,想设置成 * 上面的怎么改呀,
2我是linux系统中,在哪个文件中开启domxml扩展呀,
1 为何我换了下面的一段xml内容就运行不了,格式还是utf-8,如何才能运行下面的xml内容
<root>
<SecondHouse id="217155" userid="jtzy" password="123456" del="0">
<City>南昌</City>
<Area>莲塘</Area>
<BH>XXH217155</BH>
<Simple>澄湖北路梦里水乡</Simple>
<House>2-1-1</House>
<Number></Number>
<Kind>商品房</Kind>
<Floor>6/4</Floor>
<Sunny>南北</Sunny>
<BuildArea>101.96</BuildArea>
<BuildTime></BuildTime>
<Fitment>简装</Fitment>
<FitmentTime>0</FitmentTime>
<Layout></Layout>
<Bround></Bround>
<ManagerPrice></ManagerPrice>
<Price>50</Price>
<UnitPrice></UnitPrice>
<Note></Note>
<Tel>0791-7186688;7160778;7572099</Tel>
<Linkman>信息部</Linkman>
<AddDate>2010-11-3 13:30:03</AddDate>
</SecondHouse>
<SecondHouse id="217152" userid="jtzy" password="123456" del="0">
<City>南昌</City>
<Area>红谷滩</Area>
<BH>TYS217152</BH>
<Simple>绿茵路红谷世纪花园</Simple>
<House>2-2-1</House>
<Number></Number>
<Kind>商品房</Kind>
<Floor>11/3</Floor>
<Sunny>南北</Sunny>
<BuildArea>102</BuildArea>
<BuildTime></BuildTime>
<Fitment>精装</Fitment>
<FitmentTime>0</FitmentTime>
<Layout></Layout>
<Bround></Bround>
<ManagerPrice></ManagerPrice>
<Price>85</Price>
<UnitPrice></UnitPrice>
<Note></Note>
<Tel>6530038/15270916366</Tel>
<Linkman>桃苑店</Linkman>
<AddDate>2010-11-3 12:14:01</AddDate>
</SecondHouse>
<SecondHouse id="217151" userid="jtzy" password="123456" del="0">
<City>南昌</City>
<Area>青山湖区</Area>
<BH>TYS217151</BH>
<Simple>解放西路国药厂宿舍</Simple>
<House>2-1-1</House>
<Number></Number>
<Kind>商品房</Kind>
<Floor>7/7</Floor>
<Sunny>南北</Sunny>
<BuildArea>68</BuildArea>
<BuildTime></BuildTime>
<Fitment>简装</Fitment>
<FitmentTime>0</FitmentTime>
<Layout></Layout>
<Bround></Bround>
<ManagerPrice></ManagerPrice>
<Price>34</Price>
<UnitPrice></UnitPrice>
<Note>另送一个8平米的储藏间</Note>
<Tel>6530038/15270916366</Tel>
<Linkman>桃苑店</Linkman>
<AddDate>2010-11-3 12:11:49</AddDate>
</SecondHouse>
</root>
preg_match_all("/.*\<AddDate\>.*<\/AddDate\>.*/",$xml,$AddDate);
print_r($$AddDate[0]);
print_r($$AddDate[0]);
preg_match_all('/<Simple>(.*)<\/Simple>/i',$xml,$Simple);//得到页面中BuildArea字段所有值
print_r($Simple[1]);