如何在php中从中获取文本?
我只需要显示此字符串的状态值,但我不知道如何执行:如何在php中从中获取文本?,php,Php,我只需要显示此字符串的状态值,但我不知道如何执行: Web Object ( [data] => stdClass Object ( [operations] => stdClass Object ( [384322232931] => stdClass Object ( [status] => on ) ) ) [erro
Web Object (
[data] => stdClass Object (
[operations] => stdClass Object (
[384322232931] => stdClass Object (
[status] => on
)
)
)
[error] =>
)
感谢阅读如果对象是$webobj,它将是:
$webobj->data->operations->{'384322232931'}->status
属性名称为数字时不能使用常规属性语法,需要大括号和引号,如下所述:
如果该号码是帐户ID,您可以执行以下操作:
$webobj->data->operations->{$account_id}->status
其中$account\u id包含您的帐号。看起来您想要的属性被深深嵌入,所以您可能遇到的问题是您需要检查几个子项 尝试: $status=$yourObj->data->operations->384322232931->status 我不知道这是否有帮助。我有点搞不懂字符串是什么意思,因为您发布的内容看起来像对象的打印输出 如果您试图从字符串中提取该值,那么我认为您可能在做一些不可靠的事情。我相信数字384322232931是随机的,如果是,您必须使用递归方法:
function captureStatus($data) {
$obj = (array) $data;
$key = key($obj);
if ($key === 'status') {
return $obj['status'];
} else if ($key !== NULL) {
return captureStatus($obj[$key]);
}
return NULL;
}
如果不是随机的,使用@Barmar$something->data->operations->384322232931->status的方法,{384322232931}是随机数吗?这是来自JSON吗?如果使用json_decode$json,可能会更容易,如果为true,则会得到一个数组而不是一个对象。然后,您可以使用foreach迭代操作的所有元素;是的,我发布的数据是打印输出,如果我发布了错误的数据,很抱歉。