You are here: stdClass Object - get_object_vars « PHP Programming Language « IT news, forums, messages
stdClass Object - get_object_vars

Posted by juglesh on 09/05/05 22:40

hello, i have a d/l'd class that gives an array which prints like this:

stdClass Object
(
[first name]] => stdClass Object
(
[inputtype] => text
[value] =>
[debug] => fisrt name
[validate] => yes
)

[Buttons\0]] => stdClass Object
(
[Count] => 41
[Button] => click
)

)

i cannot seem to access the values using
$thearray['first name']['inputtype']
messed with get_object_vars() a bit, but didnt get past the first
dimension.

I'm calling the class like so:

$ini = new Ini('forms.ini');
$ini->parse();
$thearray= $ini->get();

echo "<pre>";
print_r($thearray);
echo "</pre>";


Here is the class, oh, and maybe someone can see why it's putting two
end brackets on the [first name]], etc.

<?php
/**
* Ini parser
*
* Parse Ini files into a workable object
*
* @author mcvdmvs <mick@vandermostvanspijk.nl>
* @version 0.0.1
* @package sys
* @copyright GPL
* @see http://cloanto.com/specs/ini.html
*/
class Ini {
/**
* _object->sectionname->key] = value
* _object->sectionname->key[0] = value_one
* _object->sectionname->key[1] = value_two
*/
var $_data;

/**
* store filename
*/
var $file;

/**
* keep track of last section
*/
var $_last_section = '';

/**
* Start Ini and set file
*/
function Ini ($file) {
$this->file = $file;
}

/**
* Open file and load in object
*/
function parse() {
$fp = fopen ($this->file, 'r');

while ($data = fgets($fp, 4096)) {
$this->_parseIni($data);
}

return $this->_data;
}

/**
* Internal function to handle different section
*/
function _parseIni($data) {
// trim beginning and ending spaces
$data = trim($data);

// skip white lines
if (empty($data))
return;

// skip comment lines
//if (substr($data, 0, 1) == ';')
if (substr($data, 0, 1) == '#')
return;

// section
if ((substr($data, 0, 1) == '[') AND (substr($data, -1) == ']')) {
$this->_last_section = substr($data, 1, (strlen($data) - 1));
return;
}

// entry
$pos = strpos($data, '=');
if ($pos !== FALSE) { // boolean false
// set name
$name = substr($data, 0, $pos);

// set value
$value = substr ($data, ($pos + 1), (strlen($data) - $pos - 1));

// check for comma's and spaces in value, if so make array of it
if (strpos($value, ", ")) {
$list = explode (",", $value);

// unset value
$value = array();

// loop through values and add them to array
foreach ($list as $val) {
$value[] = trim($val);
}
}

// store value
$this->_data->{$this->_last_section}->$name = $value;
}
}

/**
* return parsed ini file
*/
function get() {
return $this->_data;
}
}
?>


--
thanks,
juglesh

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация