XPATH - 获取单个值而不是数组php [英] XPATH - get single value returned instead of array php

查看:571
本文介绍了XPATH - 获取单个值而不是数组php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中使用Xpath - 我知道我的查询将返回0或1个结果。



如果返回1个结果,我不希望它数组 - 这是现在返回的。我只需要该值,而不必访问结果的 [0] 元素并转换为字符串。



这是可能吗?

解决方案

使用'评估'而不是'查询' / em>,你可以做一些投射。





另外,如果你只是很烦恼,做一些事情很多次,只需编写一个功能,这就是功能背后的整个想法,对吧?


I am using Xpath in PHP - I know that my query will return either 0 or 1 results.

If 1 result is returned I do not want it as an array - which is what is returned right now. I simply want the value without having to access the [0] element of the result and cast to a string.

Is this possible?

解决方案

Using 'evaluate' instead of 'query', you can do things like casting.

Also, if you're just annoyed with doing stuff a lot of times, just write a function that does it ... that is the whole idea behind functions, right?

这篇关于XPATH - 获取单个值而不是数组php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆