RE: Little regex help please...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Eric Butera [mailto:eric.butera@xxxxxxxxx]
> Sent: Monday, October 13, 2008 12:00 PM
> To: Boyd, Todd M.
> Cc: Ryan S; php php
> Subject: Re:  Little regex help please...
> 
> On Mon, Oct 13, 2008 at 12:52 PM, Boyd, Todd M. <tmboyd1@xxxxxxxx>
> 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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux