function parseLinkAttrs($html)
    {
        $stripped = preg_replace($this->_removed_re,
                                 "",
                                 $html);

        $html_begin = $this->htmlBegin($stripped);
        $html_end = $this->htmlEnd($stripped);

        if ($html_begin === false) {
            return array();
        }

        if ($html_end === false) {
            $html_end = strlen($stripped);
        }

        $stripped = substr($stripped, $html_begin,
                           $html_end - $html_begin);

        // Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR:
        $old_btlimit = ini_set( 'pcre.backtrack_limit', -1 );

        // Try to find the <HEAD> tag.
        $head_re = $this->headFind();
        $head_match = array();
        if (!$this->match($head_re, $stripped, $head_match)) {
                     ini_set( 'pcre.backtrack_limit', $old_btlimit );
                     return array();
        }

        $link_data = array();
        $link_matches = array();

        if (!preg_match_all($this->_link_find, $head_match[0],
                            $link_matches)) {
            ini_set( 'pcre.backtrack_limit', $old_btlimit );
            return array();
        }

        foreach ($link_matches[0] as $link) {
            $attr_matches = array();
            preg_match_all($this->_attr_find, $link, $attr_matches);
            $link_attrs = array();
            foreach ($attr_matches[0] as $index => $full_match) {
                $name = $attr_matches[1][$index];
                $value = $this->replaceEntities(
                              $this->removeQuotes($attr_matches[2][$index]));

                $link_attrs[strtolower($name)] = $value;
            }
            $link_data[] = $link_attrs;
        }

        ini_set( 'pcre.backtrack_limit', $old_btlimit );
        return $link_data;
    }
function parseLinkAttrs($html)
    {
        $stripped = preg_replace($this->_removed_re,
                                 "",
                                 $html);

        $html_begin = $this->htmlBegin($stripped);
        $html_end = $this->htmlEnd($stripped);

        if ($html_begin === false) {
            return array();
        }

        if ($html_end === false) {
            $html_end = strlen($stripped);
        }

        $stripped = substr($stripped, $html_begin,
                           $html_end - $html_begin);

        // Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR:
        $old_btlimit = ini_set( 'pcre.backtrack_limit', -1 );

        // Try to find the <HEAD> tag.
        $head_re = $this->headFind();
        $head_match = array();
        if (!$this->match($head_re, $stripped, $head_match)) {
                     ini_set( 'pcre.backtrack_limit', $old_btlimit );
                     return array();
        }

        $link_data = array();
        $link_matches = array();

        if (!preg_match_all($this->_link_find, $head_match[0],
                            $link_matches)) {
            ini_set( 'pcre.backtrack_limit', $old_btlimit );
            return array();
        }

        foreach ($link_matches[0] as $link) {
            $attr_matches = array();
            preg_match_all($this->_attr_find, $link, $attr_matches);
            $link_attrs = array();
            foreach ($attr_matches[0] as $index => $full_match) {
                $name = $attr_matches[1][$index];
                $value = $this->replaceEntities(
                              $this->removeQuotes($attr_matches[2][$index]));

                $link_attrs[strtolower($name)] = $value;
            }
            $link_data[] = $link_attrs;
        }

        ini_set( 'pcre.backtrack_limit', $old_btlimit );
        return $link_data;
    }
function parseLinkAttrs ( $ html ) { $ stripped = preg_replace ( $ this -> _removed_re , "" , $ html ) ; $ html_begin = $ this -> htmlBegin ( $ stripped ) ; $ html_end = $ this -> htmlEnd ( $ stripped ) ; if ( $ html_begin === false ) { return array ( ) ; } if ( $ html_end === false ) { $ html_end = strlen ( $ stripped ) ; } $ stripped = substr ( $ stripped , $ html_begin , $ html_end - $ html_begin ) ; // Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR: $ old_btlimit = ini_set ( 'pcre.backtrack_limit' , - 1 ) ; // Try to find the <HEAD> tag. $ head_re = $ this -> headFind ( ) ; $ head_match = array ( ) ; if ( ! $ this -> match ( $ head_re , $ stripped , $ head_match ) ) { ini_set ( 'pcre.backtrack_limit' , $ old_btlimit ) ; return array ( ) ; } $ link_data = array ( ) ; $ link_matches = array ( ) ; if ( ! preg_match_all ( $ this -> _link_find , $ head_match [ 0 ] , $ link_matches ) ) { ini_set ( 'pcre.backtrack_limit' , $ old_btlimit ) ; return array ( ) ; } foreach ( $ link_matches [ 0 ] as $ link ) { $ attr_matches = array ( ) ; preg_match_all ( $ this -> _attr_find , $ link , $ attr_matches ) ; $ link_attrs = array ( ) ; foreach ( $ attr_matches [ 0 ] as $ index => $ full_match ) { $ name = $ attr_matches [ 1 ] [ $ index ] ; $ value = $ this -> replaceEntities ( $ this -> removeQuotes ( $ attr_matches [ 2 ] [ $ index ] ) ) ; $ link_attrs [ strtolower ( $ name ) ] = $ value ; } $ link_data [ ] = $ link_attrs ; } ini_set ( 'pcre.backtrack_limit' , $ old_btlimit ) ; return $ link_data ; }
Find all link tags in a string representing a HTML document and
return a list of their attributes.

@todo This is quite ineffective and may fail with the default
pcre.backtrack_limit of 100000 in PHP 5.2, if $html is big.
It should rather use stripos (in PHP5) or strpos()+strtoupper()
in PHP4 to manage this.

@param string $html The text to parse
@return array $list An array of arrays of attributes, one for each
link tag
Find all link tags in a string representing a HTML document and return a list of their attributes .