Re: preg question

From: Date: Wed, 08 Oct 2003 05:43:31 +0000
Subject: Re: preg question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165390@lists.php.net to get a copy of this message
* Thus wrote Mike J (collegesucks2@verizonmail.com): > I want to pull the title (<title>example</title>) of a webpage out of some text. > The end result being "example". What preg function should I use and can someone give me > the the code that will do it? > preg_match is what you want. And if you poke around the preg_* section abit you'll see that preg_match_all has exactly what you want: /* match all <html>content</html> matches */ preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches); Ahh.. but you say... I only want the title tag... so changing the regex to this: preg_match_all ("/(<title>)(.*)(<\/\\2>)/i", $html, $matches); Add the 'i' flag for case INsensitivity, you have your solution.. easy eh? I'll let ya do the rest :) HTH, Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/

« previous php.general (#165390) next »