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_callback(
88 return chr(hexdec($hit[1]));
92 $str = preg_replace_callback(
115 $double =
'/^"(.*)"$/';
116 $single =
"/^\'(.*)\'$/";
118 if (preg_match($double, $str, $matches)) {
120 }
else if (preg_match($single, $str, $matches)) {
140 if (is_array($tag_names)) {
141 $tag_names =
'(?:'.implode(
'|',$tag_names).
')';
144 $close =
'\/' . (($close == 1)?
'' :
'?');
149 $self_close =
'(?:\/\s*)' . (($self_close == 1)?
'' :
'?');
153 $expr = sprintf($this->_tag_expr, $close, $tag_names, $self_close);
155 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
171 $html_string = preg_replace($this->_removed_re,
175 $key_tags = array($this->
tagPattern(
'html',
false,
false),
180 'body',
'frameset',
'frame',
'p',
'div',
181 'table',
'span',
'a'),
'maybe',
'maybe'));
182 $key_tags_pos = array();
183 foreach ($key_tags as $pat) {
185 preg_match($pat, $html_string, $matches, PREG_OFFSET_CAPTURE);
187 $key_tags_pos[] = $matches[0][1];
189 $key_tags_pos[] = null;
193 if (is_null($key_tags_pos[1])) {
197 if (is_null($key_tags_pos[2])) {
198 $key_tags_pos[2] = strlen($html_string);
200 foreach (array($key_tags_pos[3], $key_tags_pos[4]) as $pos) {
201 if (!is_null($pos) && $pos < $key_tags_pos[2]) {
202 $key_tags_pos[2] = $pos;
206 if ($key_tags_pos[1] > $key_tags_pos[2]) {
211 if (!is_null($key_tags_pos[0]) && $key_tags_pos[1] < $key_tags_pos[0]) {
214 $html_string = substr($html_string, $key_tags_pos[1],
215 ($key_tags_pos[2]-$key_tags_pos[1]));
217 $link_data = array();
218 $link_matches = array();
220 if (!preg_match_all($this->
tagPattern(
'meta',
false,
'maybe'),
221 $html_string, $link_matches)) {
225 foreach ($link_matches[0] as $link) {
226 $attr_matches = array();
227 preg_match_all($this->_attr_find, $link, $attr_matches);
228 $link_attrs = array();
229 foreach ($attr_matches[0] as $index => $full_match) {
230 $name = $attr_matches[1][$index];
234 $link_attrs[strtolower($name)] = $value;
236 $link_data[] = $link_attrs;
257 foreach ($meta_tags as $tag) {
258 if (array_key_exists(
'http-equiv', $tag) &&
259 (in_array(strtolower($tag[
'http-equiv']),
260 array(
'x-xrds-location',
'x-yadis-location'))) &&
261 array_key_exists(
'content', $tag)) {
262 return $tag[
'content'];
getMetaTags($html_string)
Given an HTML document string, this finds all the META tags in the document, provided they are found ...
removeQuotes($str)
Strip single and double quotes off of a string, if they are present.
tagPattern($tag_names, $close, $self_close)
Create a regular expression that will match an opening or closing tag from a set of names...
replaceEntities($str)
Replace HTML entities (amp, lt, gt, and quot) as well as numeric entities (e.g.
getHTTPEquiv($html_string)
Looks for a META tag with an "http-equiv" attribute whose value is one of ("x-xrds-location", "x-yadis-location"), ignoring case.