[英]Php SimpleXMLElement Object to variable
Here is my Problem, below I have an Api script to manually input the xml object [user_token] to access user information based on the token. 这是我的问题,下面有一个Api脚本,用于手动输入xml对象[user_token]以基于令牌访问用户信息。 So to enter every attribute from the array I have used the code
所以要输入数组中的每个属性,我都使用了代码
foreach ($xml->result->data->users->entries->user_token as $user_token1)
echo $user_token1;
Which then gets pluged into 然后将其插入
if ($oneall_curly->get (SITE_DOMAIN . "/users/" . $user_token1 . ".xml"))
{
$result = $oneall_curly->get_result ();
print_r (($result->body));
}
So after this Im not sure what is wrong I have searched over many answers on both stack overflow as well as php.net. 因此,在此之后,我不确定是什么错误,我在堆栈溢出以及php.net上搜索了许多答案。 I am certainly no expert really just a novice at coding php but would certainly appreciate some insight into this problem or help towards the code that creates the variable $user_token1
我当然不是专家,只是从事php编程的新手,但一定会感谢您对此问题的一些见解或对创建变量$ user_token1的代码有所帮助
Thank you so very much for looking! 非常感谢您的光临!
SimpleXMLElement Object
(
[request] => SimpleXMLElement Object
(
[date] => Fri, 26 Jul 2013 12:18:36 +0200
[resource] => /users.xml??page=1&order_direction=desc
[status] => SimpleXMLElement Object
(
[flag] => success
[code] => 200
[info] => Your request has been processed successfully
)
)
[result] => SimpleXMLElement Object
(
[data] => SimpleXMLElement Object
(
[users] => SimpleXMLElement Object
(
[pagination] => SimpleXMLElement Object
(
[current_page] => 1
[total_pages] => 1
[entries_per_page] => 500
[total_entries] => 2
[order] => SimpleXMLElement Object
(
[field] => date_creation
[direction] => desc
)
)
[count] => 2
[entries] => Array
(
[0] => SimpleXMLElement Object
(
[user_token] => 11111111-4444-bbbb-1111-111111111111
[date_creation] => Wed, 24 Jul 2013 00:33:28 +0200
[date_last_login] => Wed, 24 Jul 2013 02:08:44 +0200
[num_logins] => 2
)
[1] => SimpleXMLElement Object
(
[user_token] => 22222222-5555-aaaa-2222-333333333333
[date_creation] => Wed, 24 Jul 2013 00:28:56 +0200
[date_last_login] => Thu, 25 Jul 2013 07:08:20 +0200
[num_logins] => 4
)
)
)
)
)
) )
This is the simpleXML object I have output from previous code and this 这是我从先前代码中输出的simpleXML对象,
$raw = "http://../../file.php";
$xml = simplexml_load_file($raw);
echo '<pre>';
print_r($xml);
echo '</pre>';
return $xml;
// Get an element by its id attribute
// or, loop over all of the <rate> elements
foreach ($xml->result->data->users->entries->user_token as $user_token1)
echo $user_token1;
if ($oneall_curly->get (SITE_DOMAIN . "/users/" . $user_token1 . ".xml"))
{
$result = $oneall_curly->get_result ();
print_r (($result->body));
}
//Error
else
{
$result = $oneall_curly->get_result ();
echo "Error: " . $result->http_info . "\n";
}
?>
Try this type. 尝试这种类型。
entries
is a main array. entries
是一个主数组。 so you can store one variable then you execute via foreach
因此您可以存储一个变量,然后通过
foreach
执行
<?php
$user_token = $xml->result->data->users->entries;
foreach ($user_token as $user_token1){
echo $user_token1->user_token;
}
?>
By this $xml->result->data->users->entries
通过这个
$xml->result->data->users->entries
You select this: 您选择此:
[0] => SimpleXMLElement Object
(
[user_token] => 11111111-4444-bbbb-1111-111111111111
[date_creation] => Wed, 24 Jul 2013 00:33:28 +0200
[date_last_login] => Wed, 24 Jul 2013 02:08:44 +0200
[num_logins] => 2
)
[1] => SimpleXMLElement Object
(
[user_token] => 22222222-5555-aaaa-2222-333333333333
[date_creation] => Wed, 24 Jul 2013 00:28:56 +0200
[date_last_login] => Thu, 25 Jul 2013 07:08:20 +0200
[num_logins] => 4
)
Now you have an array of 2 SimpleXMLElement Objects
. 现在,您有2个
SimpleXMLElement Objects
的数组。 Now you can foreach 现在你可以
foreach ($xml->result->data->users->entries as $entry) {
echo $entry->user_token;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.