SimplePie_Misc::get_element PHP Method

get_element() public method

public get_element ( $realname, $string )
    function get_element($realname, $string)
    {
        $return = array();
        $name = preg_quote($realname, '/');
        if (preg_match_all("/<({$name})" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\\/{$name}>|(\\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
            for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) {
                $return[$i]['tag'] = $realname;
                $return[$i]['full'] = $matches[$i][0][0];
                $return[$i]['offset'] = $matches[$i][0][1];
                if (strlen($matches[$i][3][0]) <= 2) {
                    $return[$i]['self_closing'] = true;
                } else {
                    $return[$i]['self_closing'] = false;
                    $return[$i]['content'] = $matches[$i][4][0];
                }
                $return[$i]['attribs'] = array();
                if (isset($matches[$i][2][0]) && preg_match_all('/[\\x09\\x0A\\x0B\\x0C\\x0D\\x20]+([^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x2F\\x3E][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x2F\\x3D\\x3E]*)(?:[\\x09\\x0A\\x0B\\x0C\\x0D\\x20]*=[\\x09\\x0A\\x0B\\x0C\\x0D\\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x22\\x27\\x3E][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) {
                    for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) {
                        if (count($attribs[$j]) === 2) {
                            $attribs[$j][2] = $attribs[$j][1];
                        }
                        $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
                    }
                }
            }
        }
        return $return;
    }

Usage Example

 /**
  * @dataProvider firefoxtests
  */
 public function test_from_file($data)
 {
     $locator = new SimplePie_Locator($data, 0, null, 'MockSimplePie_File', false);
     $expected = SimplePie_Misc::get_element('link', $data->body);
     $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all);
     $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself');
     $this->assertInstanceOf('MockSimplePie_File', $feed);
     $expected = array_map(array(get_class(), 'map_url_attrib'), $expected);
     $success = array_filter($expected, array(get_class(), 'filter_success'));
     $found = array_map(array(get_class(), 'map_url_file'), $all);
     $this->assertEquals($success, $found);
 }
All Usage Examples Of SimplePie_Misc::get_element