|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 . 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. :-) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
> -----Original Message-----
> From: Ryan S [mailto:genphp@yahoo.com] > Sent: Monday, October 13, 2008 11:33 AM > To: php php > Subject: [php] Little regex 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 . > > 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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Mon, Oct 13, 2008 at 12:52 PM, Boyd, Todd M. <tmboyd1@ccis.edu> wrote:
>> -----Original Message----- >> From: Ryan S [mailto:genphp@yahoo.com] >> Sent: Monday, October 13, 2008 11:33 AM >> To: php php >> Subject: [php] Little regex 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 . >> >> 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 \/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
> -----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 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Mon, Oct 13, 2008 at 1:04 PM, Boyd, Todd M. <tmboyd1@ccis.edu> wrote:
>> -----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 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 > > > > 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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
> /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 |
|
![]() |
| Outils de la discussion | |
|
|