metatags

eimar
17 de Mayo del 2004
como leer una pagina (archivo)...y solamente mostrar los metatags del mismo ..

gracias por su colaboración,,,

willy01
17 de Mayo del 2004
Mira:
aca te mando dos pedazos de código:
El primero es mío pero no funciona bien (no los guarda en la base)

El segundo es algo que recorte de internet (vaya a saber de donde) .

Espero que seiva de algo ...
Un saludo, Guillermo



<?
$db=mysql_connect("localhost","car","***");
mysql_select_db("car",$db);
$presult=mysql_query("select * from BETA WHERE `id` = 28");
$registro=mysql_fetch_object ($presult);
$xurl='$registro->ubic';
print ("xMETA <BR>");
print ("$xurl");
print (" <BR>");
print (" <BR>");
$meta = get_meta_tags($xurl);

print ("$meta");
print (" <BR>");

$alfa=($meta['keywords']);
$sql="UPDATE BETA SET metat=$alfa WHERE id=28";
print ("alfa <BR>");
print ("$alfa");
mysql_query($sql, $db);
mysql_close($db);
?



/************************************************
* GET_META_TAGS2
*************************************************
*
* IT IS A FIX FOR THE CURRENT VERSION OF THIS FUNCTION WITHIN PHP.
*
* THIS FUNCTION TAKES INTO ACCOUNT METATAGS WHICH SPAN MORE THAN 1
LINE.
*
* IT WILL EVEN ALLOW rn's WITHIN A name OR content DEFINITION.
*
*
*
*
*************************************************/

function get_meta_tags2($file){
# OPEN FILE
$fp = fopen($file,"r");
# INITALISE ALL FLAGS
#
# THE PURPOSE OF EACH OF THEE FLAGS IS TO TELL THE SCRIPT IF THE
CURRENT $buf VALUE IS
# A CONTINUATION OF A PREVIOUS metatag, name OR content VALUE.
# IF THE FLAG IS ACTIVE IT MEANS THAT THIS NEW LINE CONTAINS MORE
INFORMATION ABOUT THE
# metatag, name OR content.
# THE FLAGS ARE ONLY KEPT RAISED IF AN ITEM SPANS MORE THAN 1 LINE.
#
$inmeta = 0;
$inname = 0;
$incontent = 0;

# LOOP THRU FILE
while( ($buf = fgets($fp,8191)) && (!eregi("</head>",$buf,$results))
){
# CHECK FOR START OF METATAG
if( ($tmp = stristr($buf,"<meta")) || $inmeta){
# IF START OF METATAG DETECTED MAKE $buf = $tmp OTHERWISE $buf
CONTAINS CONTINUING TEXT FOR A METATAG.
if (!$inmeta)
$buf = $tmp;
# RAISE INSIDE METATAG FLAG
$inmeta = 1;
# TRY TO RETRIEVE THE BEGINNING OF NAME
$tmp = stristr($buf,"name="");

# CHECK FOR BEGINNING OF NAME OR ARE WE ALREADY INSIDE NAME
SECTION
if($tmp || $inname){
# IS THIS LINE A CONTINUATION OF THE NAME FROM THE PREVIOUS
LINE
if($inname){
$tmp = $buf; # RESET $tmp TO $buf AS stristr() FUNCTION
RETURNED A BLANK
# THIS IS THE BEGINNING OF THE NAME RETRIEVAL
}else{
$inname = 1; # RAISE $inname FLAG
$metaname = ""; # CLEAR METANAME VAR
$tmp = substr($tmp,6); # MOVE POINTER TO AFTER THE name="
}
# FIND THE CLOSE QUOTE FOR THE NAME FIELD
if($end = strpos($tmp,""")){
$metaname .= substr($tmp,0,$end); # RETRIEVE NAME PART FROM
$tmp AND APPEND TO PREVIOUS RETRIEVED VALUES.
$metaname =
strtolower(ereg_replace(".|\|+|*|?|[|]|^|(|)|\$","_",trim($met
aname))); # REMOVE SPECIAL CHARACTERS
$inname = 0; # LOWER $inname FLAG
}else{
$metaname .= $tmp; # NOT THE END OF THE NAME APPEND TO
PREVIOUS VALUES AND PROCESS NEXT LINE.
}
}

$tmp = stristr($buf,"content="");
if($tmp || $incontent){
# IS THIS LINE A CONTINUATION OF THE CONTENT FROM THE PREVIOUS
LINE
if($incontent){
$tmp = $buf; # RESET $tmp TO $buf AS stristr() FUNCTION
RETURNED A BLANK
# THIS IS THE BEGINNING OF THE CONTENT RETRIEVAL
}else{
$incontent = 1; # RAISE $incontent FLAG
$metacontent = ""; # CLEAR METACONTENT VAR
$tmp = substr($tmp,9); # MOVE POINTER TO AFTER THE content="
}
# FIND THE CLOSE QUOTE FOR THE CONTENT FIELD
if($end = strpos($tmp,""")){
$metacontent .= substr($tmp,0,$end); # RETRIEVE CONTENT PART
FROM $tmp AND APPEND TO PREVIOUS RETRIEVED VALUES.
$incontent = 0; # LOWER CONTENT FLAG
}else{
$metacontent .= $tmp; # NOT THE END OF THE CONTENT APPEND TO
PREVIOUS VALUES AND PROCESS NEXT LINE.
}

}
# CHECK FOR THE END OF THE METATAG DEFINITION
if( ($tmp = stristr($buf,">")) && !$inname && !$incontent){
$metatags[$metaname] = $metacontent;
$inmeta = 0; # LOWER METATAG FLAG
}
}

}

fclose($fp);

# RETURN METATAGS ARRAY TO USER.
return($metatags);

}