从输出中抓取数据

时间:2013-09-08 10:58:13

标签: php

我有一个对象,我正试图从中获取数据。但我似乎被卡住了,任何帮助都会很棒,谢谢。

function att($prop, $what){
$reflObj = new ReflectionObject($prop);
$get = $reflObj->getProperty('attributes');
$get->setAccessible(true);
$info = $get->getValue($prop);

foreach($info as $inf){
$reflObj = new ReflectionObject($inf);

$title = $reflObj->getProperty('name');
$title->setAccessible(true);
$description = $title->getValue($inf);

var_dump("$description");

}
}

到目前为止的输出示例:

string(11) "< Min Child"
string(9) "< Train S"
string(4) "<Pub"
string(5) "<Shop"
string(7) "Balcony"
string(4) "Bath"
string(9) "Bathrooms"
string(3) "BBQ"
string(5) "Beach"
string(9) "Bed Linen"
string(8) "Internet"
string(15) "Central Heating"
string(7) "Coast <"
string(3) "Cot"

基本上希望从每个数据中获取数据。

1 个答案:

答案 0 :(得分:0)

foreach($info as $inf){
$reflObj = new ReflectionObject($inf);

$title = $reflObj->getProperty('name');
$title->setAccessible(true);
$description = $title->getValue($inf);

var_dump("$description");

}

将此行更改为:

$everything = array();
foreach($info as $inf){
    $reflObj = new ReflectionObject($inf);

    $title = $reflObj->getProperty('name');
    $title->setAccessible(true);
    $description = $title->getValue($inf);

    $everything[] = $description;

}
var_dump($everything);

$everything现在是一个数组,用于保存该输出所排序的数据。访问它的值如下:

$everything[0]

将0替换为您需要的索引。例如,3将屈服于第4个成员"<Shop"

您可以使用echo打印它们:

echo $everything[0];

提醒:var_dump()是用于输出对象数据的调试工具。它永远不应该用于获取输入,因为它的实现可能因系统而异。除非特别必要,否则应从已发布的应用程序中省略所有var_dump()代码。