472,958 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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>Documents</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.
Jul 17 '05 #1
5 6880
Jane Doe wrote:
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.


Consider get_meta_tags.

http://www.php.net/manual/en/function.get-meta-tags.php

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
Jul 17 '05 #2
On Fri, 17 Oct 2003 18:26:04 +0100, John Dunlop
<jo*********@johndunlop.info> wrote:
http://www.php.net/manual/en/function.get-meta-tags.php
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";
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.


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.
Jul 17 '05 #3
On Fri, 17 Oct 2003 19:48:18 +0200, Jane Doe <ja******@acme.com>
wrote:
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:


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

Thx again
JD.
Jul 17 '05 #4
Jane Doe <ja******@acme.com> wrote in message
news:<8b********************************@4ax.com>. ..

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?


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:

http://www.php.net/get_meta_tags

Cheers,
NC
Jul 17 '05 #5
On 17 Oct 2003 11:03:27 -0700, nc@iname.com (Nikolai Chuvakhin) wrote:
Let me start with the obvious, but rather dumb, question: are you
sure that the tags are there?
Yes, since I'm the one proofreading docs before uploading them :-)
If they are, recall that PHP has >a function that does exactly what you want:
http://www.php.net/get_meta_tags


Thx, that did it :-)

JD.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google...
3
by: Phong Ho | last post by:
Hi everyone, I try to write a simple web crawler. It has to do the following: 1) Open an URL and retrieve a HTML file. 2) Extract news headlines from the HTML file 3) Put the headlines into a...
2
by: Frank | last post by:
I'm having trouble detecting whitespaces in strings. Set up this test: echo "<br>example 1:".intval(eregi("^\s","teststring")); echo "<br>example 2:".intval(eregi("^\s","test string")); ...
25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
0
by: Shakil Khan | last post by:
Hi there ... My question is about Meta Data which is automatically saved with files. For example,when an MS Office Documents is saved, it automaticaly save some extra information with the file...
0
by: Shakil Khan | last post by:
Hi there ... My question is about Meta Data which is automatically saved with some files. For example,when an MS Office Documents is saved, it automaticaly save some extra information with the...
1
by: news | last post by:
God, I have read every comment in php.net eregi and Google searched, and I have tried so many different attempts...this is the closest I've gotten to verify a variable contains only:...
4
by: Nel | last post by:
Hi all, I am struggling with understanding a small eregi problem in php4. My code: <?PHP $htmlsource = '<img src="pics/hotdog.gif"> text text <img src="pics/silly%20sausage.gif"> ';...
1
by: fade2gray | last post by:
Hi, (new to group and a php novice) I'm editing some files using exapmles for reference. (1) // if (!eregi("admin.php", $_SERVER)) { die ("Access Denied"); } (2) if ( !defined('ADMIN_FILE')...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.