pregp html title tag

This is a discussion on pregp html title tag within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi all, I have a problem with a script, I'm trying to read an html file in and grep ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-11-2003
Anthony Ogden
 
Posts: n/a
Default pregp html title tag

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.

I'm at a loss why it works if I open and save, but not if i just directly
upload the page.

Something to do with MSDOS/Windows encoding or something maybe??? If so how
would I alter my pgrep to cater for different text formats??

I'm not sure that is the case though as it doesn't matter if my </title> is
at the end of a line or not, still doesn't work unless i open and save with
DreamWeaver.

Anthony.


Reply With Quote
  #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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0