* @copyright 2004 Peter Valicek Peter Valicek */ class HtmlFormParser { /** * Core HTML Data * @access public * @var string * @see HtmlFormParser() */ var $html_data = ''; /** * Param Array of all Elemets * @access private * @var array */ var $_return = array(); /** * Form counter * @access private * @var int */ var $_counter = ''; /** * Form button Counter * @access private * @var int * @see parseForms() */ var $button_counter = ''; /** * unique identifiert for parsing * @access private * @var string * @see HtmlFormParser() */ var $_unique_id = ''; /** * HtmlFormParser Constructor * @access public * @param mixed $html_data Could be either an big array or an string */ function HtmlFormParser( $html_data ) { if ( is_array($html_data) ) { $this->html_data = join('', $html_data); } else { $this->html_data = $html_data; } $this->_return = array(); $this->_counter = 0; $this->button_counter = 0; $this->_unique_id = md5(time()); } /** * Parse all Forms in given Data * @access public * @return array */ function parseForms() { if ( preg_match_all("/.+<\/form>/isU", $this->html_data, $forms) ) { foreach ( $forms[0] as $form ) { /* * Form Details like method, action .. */ preg_match("/]/i", $form, $form_name); $this->_return[$this->_counter]['form_data']['name'] = preg_replace("/[\"'<>]/", "", $form_name[1]); preg_match("/\s]*)([^>]*)?>/is", $form, $action); $this->_return[$this->_counter]['form_data']['action'] = preg_replace("/[\"'<>]/", "", $action[1]); preg_match("/]/i", $form, $method); $this->_return[$this->_counter]['form_data']['method'] = preg_replace("/[\"'<>]/", "", $method[1]); preg_match("/\s]*)([^>]*)?>/is", $form, $enctype); $this->_return[$this->_counter]['form_data']['enctype'] = preg_replace("/[\"'<>]/", "", $enctype[1]); /* * $/im", $form, $hiddens) ) { foreach ( $hiddens[0] as $hidden ) { $this->_return[$this->_counter]['form_elemets'][$this->_getName($hidden)] = array( 'type' => 'hidden', 'value' => $this->_getValue($hidden) ); } } /* * /iU", $form, $texts) ) { foreach ( $texts[0] as $text ) { $this->_return[$this->_counter]['form_elemets'][$this->_getName($text)] = array( 'type' => 'text', 'value' => $this->_getValue($text) ); } } /* * /iU", $form, $passwords) ) { foreach ( $passwords[0] as $password ) { $this->_return[$this->_counter]['form_elemets'][$this->_getName($password)] = array( 'type' => 'password', 'value' => $this->_getValue($password) ); } } /* *