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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
"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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|