RE: [PHP] Little regex help please...
| From: | Boyd, Todd M. | Date: | Mon, 13 Oct 2008 18:18:22 +0000 |
| Subject: | RE: [PHP] Little regex help please... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281833@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jim Lucas [mailto:lists@cmsws.com]
> Sent: Monday, October 13, 2008 12:13 PM
> To: Ryan S
> Cc: Eric Butera; Boyd, Todd M.; php php
> Subject: Re: [PHP] Little regex help please...
>
> Too quick on the reply....
>
> forgot not to escape the forward slash on the closing title tag
>
> preg_match('#<title>([^<]*)</title>#iU',$data,$match);
That'll do, Jim. :)
I also thought it worth mentioning that by telling a catch-all character
sequence (.*) not to be "greedy", another viable solution would be this:
preg_match('#<title>(.*?)</title>#iU', $data, $match);
The ? will stop it when it reaches </title> through back-tracking.
Probably less-efficient in more complex regex patterns, but I find it
can help make the patterns more readable at-a-glance in regex-heavy code
blocks.
Sorry.. a bit OT.. and the OP has already been answered. Meh.
Todd Boyd
Web Programmer