Jump to content

Xpath results without saving to var


Digicrat

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.