View Single Post

  #2 (permalink)  
Old 07-13-2003
Janwillem Borleffs
 
Posts: n/a
Default Re: pregp html title tag


"Anthony Ogden" <anthony.ogden@removethis.blueyonder.co.uk> schreef in
bericht news:ZTzPa.14923$797.5198@news-binary.blueyonder.co.uk...
> Hi all,
>
> I have a problem with a script, I'm trying to read an html file in and

grep
> the title out of it with this code:
>
> preg_match("/<title>(.*)<\/title>/i", $html_text, $title);
> $output = $output . "<li><a href=" . $filename . ">" . $title[1] .
> "</a><br />";
>
> Now, the flat HTML pages I am greping are generate from an ASP script

(don't
> ask) and if I just copy the created html pages and pop them in with my PHP
> script then the script doesn't pick out the title.
>
> If however, before uploading to the directory my PHP script is in, I open
> the HTML file in DreamWeaver then save it again without modification,

then
> pop it in the directory, the PHP file CAN grep the title tag.
>


(.*) Doesn't match new lines, which probably causes the problem.

This means that it matches

<title> title </title>

but doesn't match

<title> title
</title>

Using the following will fix this:

preg_match("/<title>([^<]*)<\/title>/i", $html_text, $title);


HTH,
JW



Reply With Quote