Digicrat Posted September 23, 2006 Share Posted September 23, 2006 This isn't a major issue, but it is very annoying.I have an xpath expression such as:[code]$this->{XML}->xpath("/template/main/title");[/code]which I simply want to echo directly to the programs output at this point. Xpath always returns its result as an array, however I know for a fact that there will always be exactly one result for this query. I would like to put:[code]echo ($this->{XML}->xpath("/template/main/title"))[0];[/code]however PHP5 considers this a syntax error. Is this a bug, or just a quirk of PHP syntax? I know I've done shortcuts like that with other programming languages on the results of a function call.Adding an extra variable just for one-time usage is simply annoying and (possibly) inefficient. Thanks. Link to comment https://forums.phpfreaks.com/topic/21791-xpath-results-without-saving-to-var/ Share on other sites More sharing options...
Barand Posted September 23, 2006 Share Posted September 23, 2006 Does this help?[code]<?php$xml = simplexml_load_file('myfile.xml');$a = $xml->xpath('template/main');foreach ($a as $item) { echo (string)$item->title,'<br>';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/21791-xpath-results-without-saving-to-var/#findComment-97369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.