Parser Fopen

cfidus -  
 cfidus -
Bonjour,
J'aimerai svp à l'aide de la fonction Fopen
parser une page web, et récupérer le titre de la page
je sais qu'il faut utilisé ca:
("<title>(.*)</title>");
mais je ne sais pas comment l'utilisr
pouvez vous m'aider svp ?
merci

4 réponses

cfidus
 
je n'arrive pas à utiliser ce code..

<?php

$file = "http://www.avocatparis.org/Eannuaire/Resultat2.aspx?cnbf=66576";
$contenu = fread(fopen($file, "r"), filesize($file));
preg_match_all("|<title>(.*)</title>|U", $contenu, $titre);

/* le \d signifie n'importe quelle décimale */
/* le .* signifie n'importe quel caractère '.' présent de 0 à n fois '*' */

?>
0
cfidus
 
ca non plus ca marche pas:

<?php
$page_title = "n/a";
$meta_descr = "n/a";
$meta_keywd = "n/a";

if ($handle = @fopen("http://www.avocatparis.org/Eannuaire/Resultat2.aspx?cnbf=66576", "r")) {
$content = "";
while (!feof($handle)) {
$part = fread($handle, 1024);
$content .= $part;
if (eregi("</head>", $part)) break;
}
fclose($handle);
$lines = preg_split("/\r?\n|\r/", $content); // turn the content in rows
$is_title = false;
$is_descr = false;
$is_keywd = false;
$close_tag = ($xhtml) ? " />" : ">"; // new in ver. 1.01
foreach ($lines as $val) {
if (eregi("<title>(.*)</title>", $val, $title)) {
$page_title = $title[1];
$is_title = true;
}
if (eregi("<meta name=\"description\" content=\"(.*)\"([[:space:]]?/)?>", $val, $descr)) {
$meta_descr = $descr[1];
$is_descr = true;
}
if (eregi("<meta name=\"keywords\" content=\"(.*)\"([[:space:]]?/)?>", $val, $keywd)) {
$meta_keywd = $keywd[1];
$is_keywd = true;
}
if ($is_title && $is_descr && $is_keywd) break;
}
}
echo "$page_title<br>";
echo "$meta_descr<br>";
echo "$meta_keywd<br>";
?>
0
cfidus
 
ca non plus :

<?php 
$title = "n/a";
    
if ($fp = @fopen('http://www.avocatparis.org/Eannuaire/Resultat2.aspx?cnbf=66576', 'r' )) {

    $cont = "";
    
    // read the contents
    while( !feof( $fp ) ) {
       $buf = trim(fgets( $fp, 4096 )) ;
       $cont .= $buf;
    }

    // get tag contents
    @preg_match( "<title>(.*)</title>", $cont, $match );
    
    // tag contents
    $title = strip_tags(@$match[1]); 
} 

echo $match[1];
echo $title;
?>


quelqu'un peux m'aider !!
0
cfidus
 
c'est bon j'ai trouvé ! merci de ne PAS m'avoir aidé :)

<?php

$page = "http://www.avocatparis.org/Eannuaire/Resultat2.aspx?cnbf=66576";

    // tags
    $start = '<title>';
    $end = '<\/title>';

    // open the file
    $fp = fopen( $page, 'r' );

    $cont = "";

    // read the contents
    while( !feof( $fp ) ) {
        $buf = trim( fgets( $fp, 4096 ) );
        $cont .= $buf;
    }
    
    // get tag contents
    preg_match( "/$start(.*)$end/s", $cont, $match );

    // tag contents
    $contents = $match[ 1 ]; 

echo $contents;

?>
0