View Single Post
Old 02-27-2005, 06:48 PM   #6
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Yep, preg_match matches on the first h2 tag. Try the following instead:
Code:
//extracts title
if (preg_match_all('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs,PREG_SET_ORDER)) {
    $title = trim($regs[X][1]); // set X to a number
}
else {
    $title = "";
}
Where X in the above code indicates the h2 tag to match: $regs[0][1] means to match the first h2 tag, $regs[1][1] means to match the second h2 tag, $regs[2][1] means to match the third h2 tag, and so on.

You could also do something like the following:
Code:
    // assumes there are at least three h2 tags
    $title = trim($regs[0][1]." ".$regs[1][1]." ".$regs[2][1]);
A thing to remember is that whatever you set X to, that will be used across all pages, so there needs to be at least X+1 h2 tags in all pages.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote