RE: [PHP] Little regex help please...
| From: | Boyd, Todd M. | Date: | Mon, 13 Oct 2008 17:04:38 +0000 |
| Subject: | RE: [PHP] Little regex help please... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281824@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Eric Butera [mailto:eric.butera@gmail.com]
> Sent: Monday, October 13, 2008 12:00 PM
> To: Boyd, Todd M.
> Cc: Ryan S; php php
> Subject: Re: [PHP] Little regex help please...
>
> On Mon, Oct 13, 2008 at 12:52 PM, Boyd, Todd M. <tmboyd1@ccis.edu>
> wrote:
> > I don't believe you need both the / and the # for delimiters in your
> > RegEx. Try using just # (since / is actually going to be in the text
> > you're searching for) like this:
> >
> > <?php
> > $data =
> >
> > file_get_contents("http://www.youtube.com/watch?v=oQ2dKXGAjNg");
> > preg_match('#<title>([^<]*)</title>#iU', $data, $match);
> > $title = $match[1];
> > echo $title;
> > ?>
>
> You can also escape the / like \/.
Very true... but I think everything gets a bit convoluted when you escape your forward-slashes
instead of just choosing a more convenient delimiter--especially when URLs are involved. I've
seen a few regex that look ridiculous for that very reason: /http:\/\/www\.asdf\.com\/blah\/foobar\.php/i
... looks like a zig-zaggy mess. :)
My 2c,
Todd Boyd
Web Programmer