PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mzfp2
Forum Contributor
Posts: 137 Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:
Post
by mzfp2 » Sat Mar 12, 2005 7:30 am
Just a quick question,
How can I extract the title of a document using regular expressions? ie
<title>AllJammin</title>
should return me AllJammin
Any help would be greatly appreciated.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sat Mar 12, 2005 7:43 am
Code: Select all
preg_match('/<title>(.*?)<\/title>/i', $string, $matches);
echo $matches[1];
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 12, 2005 8:47 am
you may want to use an 's' modifier as well. in case the title container parts are on seperate lines.