Re: [PHP] Little regex help please...

2008-10-14 Thread Richard Heyes
 /http:\/\/www\.asdf\.com\/blah\/foobar\.php/i ... looks like a zig-zaggy 
 mess. :)

Perhaps it was meant to... :-)

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Little regex help please...

2008-10-13 Thread Ryan S
Hello!

Here's a regex that I got off the web that I am trying to modify for my needs, 
I suck at regex so desperately need some help.

Basically, am trying to get a remote webpage and get the value between the 
title tags, note that it should get the values regardless if title is upper 
or lower case (case insensitive)

?php
$data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
preg_match('/#title([^]*)/title#/iU',$data,$match);
$title=$match[1]; 
echo $title;
?

This is the error that i am getting when running the above:

Warning: preg_match() [function.preg-match]: Unknown modifier 't' in 
C:\wamp\www\ezee\tests\get
_remote_title.php on line 3

TIA,
Ryan




 --
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)



  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Little regex help please...

2008-10-13 Thread Boyd, Todd M.
 -Original Message-
 From: Ryan S [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 13, 2008 11:33 AM
 To: php php
 Subject: [PHP] Little regex help please...
 
 Hello!
 
 Here's a regex that I got off the web that I am trying to modify for
my
 needs, I suck at regex so desperately need some help.
 
 Basically, am trying to get a remote webpage and get the value between
 the title tags, note that it should get the values regardless if
 title is upper or lower case (case insensitive)
 
 ?php
 $data =
 file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
 preg_match('/#title([^]*)/title#/iU',$data,$match);
 $title=$match[1];
 echo $title;
 ?
 
 This is the error that i am getting when running the above:
 
 Warning: preg_match() [function.preg-match]: Unknown modifier 't' in
 C:\wamp\www\ezee\tests\get
 _remote_title.php on line 3

Ryan,

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;
?

HTH,


Todd Boyd
Web Programmer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little regex help please...

2008-10-13 Thread Eric Butera
On Mon, Oct 13, 2008 at 12:52 PM, Boyd, Todd M. [EMAIL PROTECTED] wrote:
 -Original Message-
 From: Ryan S [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 13, 2008 11:33 AM
 To: php php
 Subject: [PHP] Little regex help please...

 Hello!

 Here's a regex that I got off the web that I am trying to modify for
 my
 needs, I suck at regex so desperately need some help.

 Basically, am trying to get a remote webpage and get the value between
 the title tags, note that it should get the values regardless if
 title is upper or lower case (case insensitive)

 ?php
 $data =
 file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
 preg_match('/#title([^]*)/title#/iU',$data,$match);
 $title=$match[1];
 echo $title;
 ?

 This is the error that i am getting when running the above:

 Warning: preg_match() [function.preg-match]: Unknown modifier 't' in
 C:\wamp\www\ezee\tests\get
 _remote_title.php on line 3

 Ryan,

 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;
 ?

 HTH,


 Todd Boyd
 Web Programmer

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



You can also escape the / like \/.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Little regex help please...

2008-10-13 Thread Boyd, Todd M.
 -Original Message-
 From: Eric Butera [mailto:[EMAIL PROTECTED]
 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. [EMAIL PROTECTED]
 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





Re: [PHP] Little regex help please...

2008-10-13 Thread Ryan S
Hey Todd, Eric,

Thanks for replying.

 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 \/.


Ok, I changed it to:
?php
$data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
preg_match('/#title([^]*)\/title#iU',$data,$match);
$title=$match[1]; 
echo $title;
?
And this is the error i am getting:

Warning:  preg_match() [function.preg-match]: No ending delimiter '/' found in 
C:\wamp\www\ezee\tests\get_remote_title.php on line 3



  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little regex help please...

2008-10-13 Thread Jim Lucas
Ryan S wrote:
 Hey Todd, Eric,
 
 Thanks for replying.
 
 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 \/.
 
 
 Ok, I changed it to:
 ?php
 $data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
 preg_match('/#title([^]*)\/title#iU',$data,$match);
 $title=$match[1]; 
 echo $title;
 ?
 And this is the error i am getting:
 
 Warning:  preg_match() [function.preg-match]: No ending delimiter '/' found 
 in C:\wamp\www\ezee\tests\get_remote_title.php on line 3
 
 
 
   
 

Take off the first /

preg_match('#title([^]*)\/title#iU',$data,$match);
-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little regex help please...

2008-10-13 Thread Jim Lucas
Ryan S wrote:
 Hey Todd, Eric,
 
 Thanks for replying.
 
 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 \/.
 
 
 Ok, I changed it to:
 ?php
 $data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
 preg_match('/#title([^]*)\/title#iU',$data,$match);
 $title=$match[1]; 
 echo $title;
 ?
 And this is the error i am getting:
 
 Warning:  preg_match() [function.preg-match]: No ending delimiter '/' found 
 in C:\wamp\www\ezee\tests\get_remote_title.php on line 3
 
 
 
   
 

Too quick on the reply

forgot not to escape the forward slash on the closing title tag

preg_match('#title([^]*)/title#iU',$data,$match);

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little regex help please...

2008-10-13 Thread Eric Butera
On Mon, Oct 13, 2008 at 1:04 PM, Boyd, Todd M. [EMAIL PROTECTED] wrote:
 -Original Message-
 From: Eric Butera [mailto:[EMAIL PROTECTED]
 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. [EMAIL PROTECTED]
 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





Well that is a bit extreme, but I understand your point.  If it were 1
character I'd still stick with /'s and escape one though.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Little regex help please...

2008-10-13 Thread Leon du Plessis

-Original Message-
From: Ryan S [mailto:[EMAIL PROTECTED] 
Sent: 13 October 2008 07:09 PM
To: Eric Butera; Boyd, Todd M.
Cc: php php
Subject: Re: [PHP] Little regex help please...

Hey Todd, Eric,

Thanks for replying.

 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 \/.


Ok, I changed it to:
?php
$data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);
preg_match('/#title([^]*)\/title#iU',$data,$match);
$title=$match[1]; 
echo $title;
?
And this is the error i am getting:

Warning:  preg_match() [function.preg-match]: No ending delimiter '/' found
in C:\wamp\www\ezee\tests\get_remote_title.php on line 3


 Sorry forgot to include the list in my post to you

Here is another solution if you don't want to play around too much with
regex:

?php
$data = file_get_contents(http://www.youtube.com/watch?v=oQ2dKXGAjNg;);

$strt = strpos($data,title)+7;
$end = strpos($data,/title);
$len = $end - $strt;

$title= substr($data,$strt,$len);

echo $title
?

Produces:
YouTube - REALLY funny ad

As mentioned, you can probably neaten this up a bitregex may be too
complex for the simple requirement needed ?

But for fun, it will be nice to see get if preg_match can do it at some
stage :-)

Regards,

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Little regex help please...

2008-10-13 Thread Boyd, Todd M.
 -Original Message-
 From: Jim Lucas [mailto:[EMAIL PROTECTED]
 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




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little regex help please...

2008-10-13 Thread Ryan S
Thanks guys, I appreciate the help.

Cheers!
R



  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php