HTML_Functions - <?php / / $Id$ /* * HTML Functions -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
<?php // $Id$ / /** * HTML Functions - common functions for extracting data from HTML * * @author Keyvan Minoukadeh <keyvan@k1m.com> */ class HTML_Functions { /** * Find (used by HTML_Parser callback functions) * @var mixed */ var $find; /** * Result (used by HTML_Parser callback functions) * @var mixed */ var $result; /** * HTML Parser * @var object HTML_Parser */ var $parser; function HTML_Functions() { } function create_parser() { if (!isset($this->parser)) { // require HTML_Parser from HTTP Navigator classes. require_once(HTTPNAV_ROOT.'HTML_Parser.php'); $this->parser =& new HTML_Parser; } $this->parser->set_ignore_tags(null); $this->parser->set_report_tags(null); } /** * Reset vars */ function reset_vars() { $this->find = null; $this->result = null; } /** * Get link url * * Returns URL string for link named <var>$link_name</var> * Example: * <code> * $html = '<a href="http://www.domain.com/bla/bla.html">Great Site</a>';
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
* echo $html_functions->get_link_url($html, 'Great Site'); * // prints 'http://www.domain.com/bla/bla.html' * </code> * * @return string returns false if value not found */ function get_link_url($html, $link_name) { if (preg_match('/<a\s+.*?href\s*=\s*(["\']?) (.*?)\1[^>]*>'.preg_quote($link_name, '/').'/i', $html, $match)) { return $match[2]; } return false; } /** * Get string after * * Returns string found just after <var>$text_before</var> (after removing * space and quotes) * @return string returns false if value not found */ function get_string_after($html, $text_before) { if (preg_match('/'.preg_quote($text_before, '/').'["\' ]*([^"\' <>]+)/i', $html, $match)) { return $match[1]; } return false; } /** * Get input value * * Get value of input tag whose name attribute value is * <var>$input_name</var> * Example: * <code> * $html = '<form> * <input type="hidden" name="surname" value="Smith" /> * </form>'; * echo $html_func->get_input_value_by_name($html, 'surname'); * // results in 'Smith' being printed * </code> * * @return string returns false if value not found * @see _cb_get_input_value_by_name() */ { $this->reset_vars(); $this->find = $input_name; $this->create_parser(); $this->parser->set_report_tags('input'); $this->parser->set_start_element_handler(array(&$this, '_cb_get_input_value_by_name')); $this->parser->parse($html, true); if (isset($this->result)) {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/31/2011 for the course CS 302 taught by Professor J.parker during the Spring '08 term at University of Texas at Austin.

Page1 / 7

HTML_Functions - &lt;?php / / $Id$ /* * HTML Functions -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online