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. 5 6900
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
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.
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.
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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"));
...
|
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...
|
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...
|
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...
|
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:...
|
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"> ';...
|
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')...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |