From: "Curt Zirzow" <[EMAIL PROTECTED]>
> * Thus wrote James Hatridge ([EMAIL PROTECTED]):
> > 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...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to