Re: I suck at regular expressions!
| From: | _lallous | Date: | Thu, 15 Nov 2001 11:01:08 +0000 |
| Subject: | Re: I suck at regular expressions! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74697@lists.php.net to get a copy of this message | ||
try that!
<?
$mem='
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
</body>
</html>
';
if (preg_match('/<title>(.+?)<\/title>/is', $mem, $matches))
{
echo "title is:$matches[1]";
}
?>
"Richard S. Crawford" <rscrawford@mossroot.com> wrote in message
news:5.1.0.14.0.20011114232718.02936db8@pop3.norton.antivirus...
I am trying to get the title of an html file... you know, the string
between the < title > and < /title > tags...
Here is the function I've got so far:
function fileTitle($fileName) {
$myFile = fopen($fileName, "r");
$myText="";
while (!feof($myFile)) {
$myText .= fgets($myFile,255);
}
fclose($myFile);
if (eregi("<TITLE>(.+)</TITLE>",$myText,$theTitle)) return
$theTitle[0];
else return "(No Title)";
}
The trouble is, it always returns "(No Title)", regardless of whether the
file has a title defined in the header or not.
I suspect I'm doing something fundamentally wrong. Can anyone set me
straight?
Sliante,
Richard S. Crawford
http://www.mossroot.com
mailto:rscrawford@mossroot.com
AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford
"It is only with the heart that we see rightly; what is essential is
invisible to the eye." --Antoine de Saint Exupéry
"Push the button, Max!"