我正在学习如何在php中使用simplexmlelement函数,直到现在一直都很好。我已经设法从xml的一个部分获取feed部分的所有内容
[paragraphs] => SimpleXMLElement Object ( [paragraph] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 [type] => 0 ) [name] => Ground Floor - Private Entrance Hall [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 3.94m max x 2.44m max (inc stairs) [imperial] => 12'11 max x 8'0 max (inc stairs) [mixed] => 3.94m max x 2.44m max (inc stairs) (12'11 max x 8' ) [text] => Private entrance with composite entrance door opening into the ground floor section of the property. The entrance hall has a radiator and doors off to both a ground floor w.c. and Bedroom 2. Stairs also rise from the entrance hall to the first floor. ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 2 [type] => 0 ) [name] => Ground Floor WC [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 1.45m x 1.17m [imperial] => 4'9 x 3'10 [mixed] => 1.45m x 1.17m (4'9 x 3'10) ) [text] => Serving the adjacent ground floor bedroom with close coupled w.c. and ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 3 [type] => 0 ) [name] => Bedroom 2 [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 2.44m x 2.11m [imperial] => 8'0 x 6'11 [mixed] => 2.44m x 2.11m (8'0 x 6'11) ) [text] => With double glazed window to rear. Radiator. ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 4 [type] => 0 ) [name] => SimpleXMLElement Object ( ) [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => SimpleXMLElement Object ( ) [imperial] => SimpleXMLElement Object ( ) [mixed] => SimpleXMLElement Object ( ) ) [text] => Returning to the hallway stairs rise to the first floor landing. ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 5 [type] => 0 ) [name] => First Floor - Landing [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => SimpleXMLElement Object ( ) [imperial] => SimpleXMLElement Object ( ) [mixed] => SimpleXMLElement Object ( ) ) [text] => with doors off to the following first floor accommodation ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 6 [type] => 0 ) [name] => Bedroom 1 [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 2.67m x 2.49m (plus built in wardrobes) [imperial] => 8'9 x 8'2 (plus built in wardrobes) [mixed] => 2.67m x 2.49m (plus built in wardrobes) (8'9 x 8'2 ) [text] => A well proportioned double bedroom with sliding doors to two sets of built in wardrobes. Double glazed window to rear. Radiator. ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 7 [type] => 0 ) [name] => Bathroom [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 2.11m x 1.68m [imperial] => 6'11 x 5'6 [mixed] => 2.11m x 1.68m (6'11 x 5'6) ) [text] => Fitted with a three piece suite comprising bath with shower over and screen to side. Pedestal wash hand basin and close coupled w.c. Radiator. Obscured glazed, double glazed window. Part tiling to walls. Extractor fan. Spot lights inset to ceiling. ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8 [type] => 0 ) [name] => Sitting / Dining Room [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 6.05m x 3.07m [imperial] => 19'10 x 10'1 [mixed] => 6.05m x 3.07m (19'10 x 10'1) ) [text] => An excellent dual purpose reception room of surprising proportions with ample space for both seating and dining in comfort. The room has good natural light entering the room through PVCu double glazed double doors to a "Juliette" balcony and also through a double glazed window to the rear. TV aerial point. Two radiators. Arch through to the kitchen. ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 9 [type] => 0 ) [name] => Kitchen [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => 2.34m x 2.21m [imperial] => 7'8 x 7'3 [mixed] => 2.34m x 2.21m (7'8 x 7'3 ) ) [text] => Fitted with a range of both base and eye level storage units as well as built in appliances. The base level units being surmounted by rolled edge work surfaces. Complementary splash back tiling. Inset stainless steel sink unit with mixer tap. Built in oven above which is a four ring gas hob with fitted extractor hood over. Wall mounted gas boiler. Space for white goods, plumbing for automatic washing machine. ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 10 [type] => 0 ) [name] => Outside [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => SimpleXMLElement Object ( ) [imperial] => SimpleXMLElement Object ( ) [mixed] => SimpleXMLElement Object ( ) ) [text] => To the front of the property there is a designated car parking space. ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 11 [type] => 0 ) [name] => Further Information [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => SimpleXMLElement Object ( ) [imperial] => SimpleXMLElement Object ( ) [mixed] => SimpleXMLElement Object ( ) ) [text] => Any fixtures and fittings not mentioned in these details are excluded from the sale price. No services or appliances which may have been included in these details have been tested and therefore cannot be guaranteed to be in good working order. Nothing therein shall be a warranty or condition and neither the Vendor nor ourselves will be liable to the Purchaser in respect of any mis-statement or misrepresentation made at or before the date hereof by the Vendor, his servants or agents or otherwise. COUNCIL TAX BAND (A) : EPC RATING C (75): SERVICES: All mains services are connected to the property. VIEWING:By telephone appointment with ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 12 [type] => 0 ) [name] => Personal Interest [file] => SimpleXMLElement Object ( ) [dimensions] => SimpleXMLElement Object ( [metric] => SimpleXMLElement Object ( ) [imperial] => SimpleXMLElement Object ( ) [mixed] => SimpleXMLElement Object ( ) ) [text] => We are obliged to inform you that this property is owned by a director/senior partner of. ) ) )
所以我尝试了不同的方法将值输入到变量中但是收到错误:解析错误:语法错误,意外' 0' (T_LNUMBER),期待标识符(T_STRING)或变量(T_VARIABLE)或' {'或者' $'
我已经厌倦了以下
$feed = file_get_contents('http://mysite.co.uk/inc/feed.xml');
$xml = simplexml_load_string($feed);
echo 'Desc: ' . $xml->paragraphys->paragraph->0->id;
echo 'Desc: ' . $xml->paragraphys->paragraph->$0->id;
我刚刚尝试了一个foreach循环,但这不起作用
foreach($xml->paragraphys->paragraph as $p) {
$paragraph = new Paragraph;
echo '<br/>Par: ' . $p->id;
}
非常感谢任何帮助 干杯 舒卡
答案 0 :(得分:1)
<?php
echo 'Desc:'.(string)$xml->paragraphs->paragraph[0]->id;
?>