Extract Document Title

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

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Extract Document Title

Post by mzfp2 »

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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

preg_match('/<title>(.*?)<\/title>/i', $string, $matches);
echo $matches[1];
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may want to use an 's' modifier as well. in case the title container parts are on seperate lines. :)
Post Reply