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));
79 foreach ($this->_entity_replacements as $old => $new) {
80 $str = preg_replace(sprintf(
"/&%s;/", $old), $new, $str);
85 $str = preg_replace(
'~&#x([0-9a-f]+);~ei',
'chr(hexdec("\\1"))', $str);
86 $str = preg_replace(
'~&#([0-9]+);~e',
'chr(\\1)', $str);
103 $double =
'/^"(.*)"$/';
104 $single =
"/^\'(.*)\'$/";
106 if (preg_match($double, $str, $matches)) {
108 }
else if (preg_match($single, $str, $matches)) {
128 if (is_array($tag_names)) {
129 $tag_names =
'(?:'.implode(
'|',$tag_names).
')';
132 $close =
'\/' . (($close == 1)?
'' :
'?');
137 $self_close =
'(?:\/\s*)' . (($self_close == 1)?
'' :
'?');
141 $expr = sprintf($this->_tag_expr, $close, $tag_names, $self_close);
143 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
159 $html_string = preg_replace($this->_removed_re,
163 $key_tags = array($this->
tagPattern(
'html',
false,
false),
168 'body',
'frameset',
'frame',
'p',
'div',
169 'table',
'span',
'a'),
'maybe',
'maybe'));
170 $key_tags_pos = array();
171 foreach ($key_tags as $pat) {
173 preg_match($pat, $html_string, $matches, PREG_OFFSET_CAPTURE);
175 $key_tags_pos[] = $matches[0][1];
177 $key_tags_pos[] = null;
181 if (is_null($key_tags_pos[1])) {
185 if (is_null($key_tags_pos[2])) {
186 $key_tags_pos[2] = strlen($html_string);
188 foreach (array($key_tags_pos[3], $key_tags_pos[4]) as $pos) {
189 if (!is_null($pos) && $pos < $key_tags_pos[2]) {
190 $key_tags_pos[2] = $pos;
194 if ($key_tags_pos[1] > $key_tags_pos[2]) {
199 if (!is_null($key_tags_pos[0]) && $key_tags_pos[1] < $key_tags_pos[0]) {
202 $html_string = substr($html_string, $key_tags_pos[1],
203 ($key_tags_pos[2]-$key_tags_pos[1]));
205 $link_data = array();
206 $link_matches = array();
208 if (!preg_match_all($this->
tagPattern(
'meta',
false,
'maybe'),
209 $html_string, $link_matches)) {
213 foreach ($link_matches[0] as $link) {
214 $attr_matches = array();
215 preg_match_all($this->_attr_find, $link, $attr_matches);
216 $link_attrs = array();
217 foreach ($attr_matches[0] as $index => $full_match) {
218 $name = $attr_matches[1][$index];
222 $link_attrs[strtolower($name)] = $value;
224 $link_data[] = $link_attrs;
245 foreach ($meta_tags as $tag) {
246 if (array_key_exists(
'http-equiv', $tag) &&
247 (in_array(strtolower($tag[
'http-equiv']),
248 array(
'x-xrds-location',
'x-yadis-location'))) &&
249 array_key_exists(
'content', $tag)) {
250 return $tag[
'content'];