views:

104

answers:

2

Im using a class that returns a rather large (I guess) array. How do I get the value of the div's class attribute - in this array its 'display:none' - Its the output from a print_r.

Here is the array: http://joe-riggs.com/large%5Farray.php

Also the class I'm using that is returning this array is simplehtmldom_1_11 - so there may be a more direct way of accessing that I don't know about that I couldnt find in the documentation.

Here' the source to my page listed above with some unsuccessful attempts:

<?PHP
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

include('simplehtmldom/simple_html_dom.php');
$myFile = "red.html";
$fh = fopen($myFile, 'r');
$page = fread($fh, filesize($myFile));
fclose($fh);
$html = str_get_html($page);
// find all span tags with class=gb1
//foreach($html->find('div[class^=entry]') as $e)
foreach($html->find('div[class*=thing id-t3]') as $e){
print_r($e);
die;

//echo $e->outertext . '<br>';
//$e->find('div#', 0)->plaintext
//$e->find('div#display:none', 0)->plaintext;

}


?>
A: 

The page you refer to looks like the output of a print_r call. It is an object, with some arrays, variables and more objects... apparently recursing alot. There's an entry in the print_r page for doing "reverse print_r". That might help you out...

More generally what you are trying to do is typically referred to as serialization/deserialization. That is converting a value from memory to a permanent (possible human-readable) representation and back out again. If possible, you may wish to use something more like json for what you are attempting.

Doug T.
A: 
foreach($your_array->find('div') as $element)
   echo $element->style;

This should output all styles of all div tags.

hakunin
How would I access that variable without a loop though? I think something like $your_array[0][1]->style?
jriggs
$divs = $your_array->find('div');$first_element = $divs[0];$first_element_style = $first_element->style;
hakunin