PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Little regex please...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Little regex please...

Réponse
 
LinkBack Outils de la discussion
Vieux 13/10/2008, 18h32   #1
Ryan S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

TIA,
Ryan




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




  Réponse avec citation
Vieux 13/10/2008, 18h52   #2
Boyd, Todd M.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] Little regex please...

> -----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
  Réponse avec citation
Vieux 13/10/2008, 18h59   #3
Eric Butera
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Little regex please...

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 \/.
  Réponse avec citation
Vieux 13/10/2008, 19h04   #4
Boyd, Todd M.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] Little regex please...

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



  Réponse avec citation
Vieux 13/10/2008, 19h13   #5
Eric Butera
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Little regex please...

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.
  Réponse avec citation
Vieux 14/10/2008, 10h26   #6
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Little regex please...

> /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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12423 seconds with 14 queries