Page 1 of 1

Extract Document Title

Posted: Sat Mar 12, 2005 7:30 am
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.

Posted: Sat Mar 12, 2005 7:43 am
by Chris Corbyn

Code: Select all

preg_match('/<title>(.*?)<\/title>/i', $string, $matches);
echo $matches[1];

Posted: Sat Mar 12, 2005 8:47 am
by feyd
you may want to use an 's' modifier as well. in case the title container parts are on seperate lines. :)