34 "<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>";
48 $this->_attr_find = sprintf(
"/%s/%s",
52 $this->_removed_re = sprintf(
"/%s/%s",
56 $this->_entity_replacements = array(
64 sprintf(
"&(%s);", implode(
"|",
65 $this->_entity_replacements));
80 $double =
'/^"(.*)"$/';
81 $single =
"/^\'(.*)\'$/";
83 if (preg_match($double, $str, $matches)) {
85 }
else if (preg_match($single, $str, $matches)) {
105 if (is_array($tag_names)) {
106 $tag_names =
'(?:'.implode(
'|',$tag_names).
')';
109 $close =
'\/' . (($close == 1)?
'' :
'?');
114 $self_close =
'(?:\/\s*)' . (($self_close == 1)?
'' :
'?');
118 $expr = sprintf($this->_tag_expr, $close, $tag_names, $self_close);
120 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
136 $html_string = preg_replace($this->_removed_re,
140 $key_tags = array($this->
tagPattern(
'html',
false,
false),
145 'body',
'frameset',
'frame',
'p',
'div',
146 'table',
'span',
'a'),
'maybe',
'maybe'));
147 $key_tags_pos = array();
148 foreach ($key_tags as $pat) {
150 preg_match($pat, $html_string, $matches, PREG_OFFSET_CAPTURE);
152 $key_tags_pos[] = $matches[0][1];
154 $key_tags_pos[] = null;
158 if (is_null($key_tags_pos[1])) {
162 if (is_null($key_tags_pos[2])) {
163 $key_tags_pos[2] = strlen($html_string);
165 foreach (array($key_tags_pos[3], $key_tags_pos[4]) as $pos) {
166 if (!is_null($pos) && $pos < $key_tags_pos[2]) {
167 $key_tags_pos[2] = $pos;
171 if ($key_tags_pos[1] > $key_tags_pos[2]) {
176 if (!is_null($key_tags_pos[0]) && $key_tags_pos[1] < $key_tags_pos[0]) {
179 $html_string = substr($html_string, $key_tags_pos[1],
180 ($key_tags_pos[2]-$key_tags_pos[1]));
182 $link_data = array();
183 $link_matches = array();
185 if (!preg_match_all($this->
tagPattern(
'meta',
false,
'maybe'),
186 $html_string, $link_matches)) {
190 foreach ($link_matches[0] as $link) {
191 $attr_matches = array();
192 preg_match_all($this->_attr_find, $link, $attr_matches);
193 $link_attrs = array();
194 foreach ($attr_matches[0] as $index => $full_match) {
195 $name = $attr_matches[1][$index];
196 $value = html_entity_decode(
199 $link_attrs[strtolower($name)] = $value;
201 $link_data[] = $link_attrs;
222 foreach ($meta_tags as $tag) {
223 if (array_key_exists(
'http-equiv', $tag) &&
224 (in_array(strtolower($tag[
'http-equiv']),
225 array(
'x-xrds-location',
'x-yadis-location'))) &&
226 array_key_exists(
'content', $tag)) {
227 return $tag[
'content'];
getHTTPEquiv($html_string)
tagPattern($tag_names, $close, $self_close)
getMetaTags($html_string)