nknk 3 Denunciar post Postado Julho 23, 2008 Como eu faço para coletar as meta tags de um site? eu gostaria de pegar as tags <title> <meta description> Compartilhar este post Link para o post Compartilhar em outros sites
hinom 5 Denunciar post Postado Julho 23, 2008 usando expressão regular exemplo: function findTag( $str, $ini, $end, $allow = '0-9,a-z,A-Z,.,_,-' ) { //denied ^\.) preg_match_all('/' . preg_quote($ini, '/') . '([' . $allow . ']+)'. preg_quote($end, '/').'/i', $str, $m ); return $m[1]; /** usage sample 1 $ini = "{:"; $end = "}"; $str = 'Name: {:company.name}<br>Address: {:company.addr}'; $out = findTag( $ini, $end, $str ); print_r ($out); */ } $ini = "{:"; $end = "}"; $str = 'Name: {:company.name}<br>Address: {:company.addr}'; $out = findTag( $str, $ini, $end ); print_r ($out); Compartilhar este post Link para o post Compartilhar em outros sites
nknk 3 Denunciar post Postado Julho 23, 2008 mas cmo eu faço para eu abrir o site. tipo o<? $url="http://www.imaster.com.br";?> Como eu acesso o site e leio o que esta em <title></title> ? Compartilhar este post Link para o post Compartilhar em outros sites
hinom 5 Denunciar post Postado Julho 24, 2008 isso é outra questão.. busque no forum, pois existem milhares de topicos sobre como ler o conteúdo de um site externo Compartilhar este post Link para o post Compartilhar em outros sites
nknk 3 Denunciar post Postado Agosto 4, 2008 Na hora que postei não sabia que palavra chave buscar, mas acabei de lembrar do topico do google (voce quis dizer) - que participei. Compartilhar este post Link para o post Compartilhar em outros sites
hinom 5 Denunciar post Postado Agosto 4, 2008 http://php.net/file_get_contents Compartilhar este post Link para o post Compartilhar em outros sites
nknk 3 Denunciar post Postado Setembro 1, 2008 Consegui, encontrei um codigo no php.net, está funcionando direito só que alguns sites da erro na porta 80, tipo o geocities, ou seja aqueles sites sem hospdagem/dominio proprios. Mas isso pode ser pq o servidor tem uma função adaptada deste get contents function getUrlData($url) { $result = false; $contents = getUrlContents($url); if (isset($contents) && is_string($contents)) { $title = null; $metaTags = null; preg_match('/<title>([^>]*)<\/title>/si', $contents, $match ); if (isset($match) && is_array($match) && count($match) > 0) { $title = strip_tags($match[1]); } preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) == 3) { $originals = $match[0]; $names = $match[1]; $values = $match[2]; if (count($originals) == count($names) && count($names) == count($values)) { $metaTags = array(); for ($i=0, $limiti=count($names); $i < $limiti; $i++) { $metaTags[$names[$i]] = array ( 'html' => htmlentities($originals[$i]), 'value' => $values[$i] ); } } } $result = array ( 'title' => $title, 'metaTags' => $metaTags ); } return $result; } function getUrlContents($url, $maximumRedirections = null, $currentRedirection = 0) { $result = false; $contents = @file_get_contents($url); // Check if we need to go somewhere else if (isset($contents) && is_string($contents)) { preg_match_all('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1) { if (!isset($maximumRedirections) || $currentRedirection < $maximumRedirections) { return getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection); } $result = false; } else { $result = $contents; } } return $contents; } $url=$n["site"];; $result = getUrlData($url); $tit=$result["title"]; $desc=$result["metaTags"]["description"]["value"]; Compartilhar este post Link para o post Compartilhar em outros sites