Eregi() to extract author meta tag?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jane Doe

    #1

    Eregi() to extract author meta tag?

    Hi

    I took a quick look in the archives, but didn't find an answer
    to this one.

    I'd like to display a list of HTML files in a directory, showing the
    author's name between brackets after the file name. I can successfully
    extract the TITLE section, but no luck with the AUTHOR part. Any idea
    why?

    <?php
    $body = "<h1>Docume nts</h1>";

    $dir = opendir(".");
    while ($item = readdir($dir)) {
    //Only HTM(L) files
    if(substr($item ,-5) == ".html" || substr($item,-4) == ".htm") {
    $fp = fopen($item, "r");
    $contents = fread($fp, filesize($item) );
    fclose($fp);

    //Works OK to extract TITLE
    eregi("<title>( .+)</title>", $contents, $regs);
    $file[$item] = $regs[1];

    //Doesn't work
    //eregi("<meta name=\"author\" content=\"(.+)\ ">', $contents,
    $regs);

    //Doesn't work
    eregi('<meta name="author" content="(.+)"> ', $contents, $regs);
    If ($regs[1])
    $author[$item] = "(Author unknown)";
    else
    $author[$item] = "(" . $regs[1] . ")";
    }
    }

    $body .= "<ul>\n";
    foreach ($file as $item => $title) {
    $body .= "<li><a href=\"" . $item . "\">" . $file[$item] . "</a> " .
    $author[$item];
    }
    $body .= "</ul>\n";

    print $body;

    ?>

    FWIW, I tried making eregi non-greedy using (.+?) or ([^"].+), and
    also used double quotes (shown above), all to no avail.

    Any tip much appreciated.

    Thank you
    JD.
  • John Dunlop

    #2
    Re: Eregi() to extract author meta tag?

    Jane Doe wrote:
    [color=blue]
    > I'd like to display a list of HTML files in a directory, showing the
    > author's name between brackets after the file name. I can successfully
    > extract the TITLE section, but no luck with the AUTHOR part.[/color]

    Consider get_meta_tags.

    Extracts all meta tag content attributes from a file and returns an array


    And remember there's no requirement for an author to (a) show her
    real name; or (b) use the so-called "author" meta tag, or any meta
    tag for that matter.

    --
    Jock

    Comment

    • Jane Doe

      #3
      Re: Eregi() to extract author meta tag?

      On Fri, 17 Oct 2003 18:26:04 +0100, John Dunlop
      <john+usenet@jo hndunlop.info> wrote:
      [color=blue]
      >http://www.php.net/manual/en/function.get-meta-tags.php[/color]

      Thx John :-)

      BTW, is there a similar API to extract the title section? It's kinda
      stupide to have PHP parse the same document twice to extra this and
      the meta tags:

      $fp = fopen($item, "r");
      $contents = fread($fp, filesize($item) );
      fclose($fp);
      eregi("<title>( .+)</title>", $contents, $regs);
      if (!$regs[1]) {
      $title = "(Title not filled)";
      } else {
      $title = $regs[1];
      }

      $tags = get_meta_tags($ item);

      if (!$tags['author']) {
      $author = "(Author not filed)";
      } else {
      $author = "(" . $tags['author'] .")";
      }
      print "<li><a href=\"$item\"> $title</a> $author";
      [color=blue]
      >And remember there's no requirement for an author to (a) show her
      >real name; or (b) use the so-called "author" meta tag, or any meta
      >tag for that matter.[/color]

      It's OK. I run a script prior to accepting a document inside our CMS,
      and reject any document that doesn't have the TITLE and AUTHOR
      sections filled.

      Thx :-)
      JD.

      Comment

      • Jane Doe

        #4
        Re: Eregi() to extract author meta tag?

        On Fri, 17 Oct 2003 19:48:18 +0200, Jane Doe <jane.doe@acme. com>
        wrote:[color=blue]
        >BTW, is there a similar API to extract the title section? It's kinda
        >stupide to have PHP parse the same document twice to extra this and
        >the meta tags:[/color]

        Stupid me :-) Just use the "descriptio n" meta tag, and be done with
        it.

        Thx again
        JD.

        Comment

        • Nikolai Chuvakhin

          #5
          Re: Eregi() to extract author meta tag?

          Jane Doe <jane.doe@acme. com> wrote in message
          news:<8bhvovkbj vrnggs0qddm7l3a fj8jt3tt0r@4ax. com>...[color=blue]
          >
          > I'd like to display a list of HTML files in a directory, showing the
          > author's name between brackets after the file name. I can successfully
          > extract the TITLE section, but no luck with the AUTHOR part. Any idea
          > why?[/color]

          Let me start with the obvious, but rather dumb, question: are you
          sure that the tags are there? If they are, recall that PHP has
          a function that does exactly what you want:

          Extracts all meta tag content attributes from a file and returns an array


          Cheers,
          NC

          Comment

          • Jane Doe

            #6
            Re: Eregi() to extract author meta tag?

            On 17 Oct 2003 11:03:27 -0700, nc@iname.com (Nikolai Chuvakhin) wrote:[color=blue]
            >Let me start with the obvious, but rather dumb, question: are you
            >sure that the tags are there?[/color]

            Yes, since I'm the one proofreading docs before uploading them :-)
            [color=blue]
            >If they are, recall that PHP has >a function that does exactly what you want:
            >http://www.php.net/get_meta_tags[/color]

            Thx, that did it :-)

            JD.

            Comment

            Working...