RE: [PHP] [!NEWBIE ALERT!] fread() question
| From: | John W. Holmes | Date: | Mon, 24 Feb 2003 03:47:16 +0000 |
| Subject: | RE: [PHP] [!NEWBIE ALERT!] fread() question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136809@lists.php.net to get a copy of this message | ||
What was suggested will work fine if the <title> and </title> are on the
same line. If someone writes the file such as
<title>
My Title
</title>
Then it will not match it. If this is a possibility for you, you'll want
to add an 's' modifier onto your pattern.
$pattern="/<title>(.*)<\/title>/is";
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
> -----Original Message-----
> From: Levi Zander [mailto:lzander@bsd.ieteng.com]
> Sent: Sunday, February 23, 2003 9:26 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] [!NEWBIE ALERT!] fread() question
>
> worked like a champ! thanks!
>
>
> "Chris Hayes" <chayes@antenna.nl> wrote in message
> news:5.1.1.6.0.20030224003758.01bfdd48@pop4.antenna.nl...
> > At 00:05 24-2-2003, you wrote:
> > >trying to parse a URL and write html code to a file, then search
the
> file
> > >for a string between <TITLE> ... </TITLE> how would I implement
the
> fread
> > >function below, and regular expressions to read the specific
conent.
> thx
> > >
> > >or is there a php function that can return the TITLE of a URL?
> > >
> > ><?php
> > >$string = implode("", file($url));
> > >$fp = fopen("temp.txt", "w");
> > >fwrite($fp, $string);
> > >fclose($fp);
> >
> > i would read in the entire file, and use a 'regular expression' such
as
> > ereg() http://nl.php.net/manual/nl/function.ereg.php
> > explained on
> > http://www.phpbuilder.com/columns/dario19990616.php3
> >
> > or preg_match
> > http://nl.php.net/manual/nl/function.preg-match.php
> >
> > I think this may work, with the $string from your code:
> > $pattern="/<title>(.*)<\/title>/i";
> > preg_match($pattern, $string, $matches);
> > $title=$matches[1];
> > echo $title;
> >
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php