Re: Search question ..
| From: | CPT John W. Holmes | Date: | Wed, 23 Jul 2003 20:16:39 +0000 |
| Subject: | Re: Search question .. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156523@lists.php.net to get a copy of this message | ||
From: "Curt Zirzow" <curt@zirzow.dyndns.org>
> * Thus wrote James Hatridge (James.Hatridge@epost.de):
> > I've got a search page written for my web site. I can find the html page
I
> > want by keyword. Now I need to get the title of that page in to a
variable.
> > In other words I have a file name, for example Summerbulletin.html. I
now
> > need to get the line "<title> Summer 2003 </title>" in to a
> > variable.
How do
> > I tell html or PHP what I want? (I hope that I am understandable, I'm
still
> > new at this. )
> >
> > Right now I output the search results in to a chart that shows
> > "Summerbulletin.html". What I would like to show is "Summer 2003".
>
> preg_match('#\<title\>(.*)\</title\>#im', $text, $matches):
I don't think you have to escape the < and > characters, do you? Also,
what's the 'm' modifier for? (I know what it does, why are you using it
here?)
Also, if there's ever a case where could have
<title>
My Title
</title>
i.e. things spread over multiple lines, then you'll need:
preg_match('#<title>(.*)</title>#is',$text,$matches);
or, even better (ungreedy)
preg_match('#<title>([^<]+)</title>#i',$text,$matches);
The 's' modifier will allow you to match the title even though it's over
multiple lines with the first regex example. It's not needed in the second.
---John Holmes...