Getting h2 and h3 headings from text in a recordset
Hi Ray, I have some HTML text in a database and I need to extract the h2 and h3 headings from the text to construct a table of contents. I found the following bit of code whilst searching online, but having tried to replace the html text example with the contents of the recordset, I can't get it to work. This is the code:
<?php
$headings='
<h2>This is heading h2</h2>
<h3>This is heading h3</h3>
';
function fnextractHeadins($headingtag, $headings)
{
$headingText = '';
preg_match_all( '|<'.$headingtag.'>(.*)</'.$headingtag.'>|iU', $headings, $headings );
foreach($headings[0] as $headh2val)
{
$headingText.=$headh2val;
}
return $headingText;
}
echo fnextractHeadins('h2', $headings);
echo fnextractHeadins('h3', $headings);
?>
I want to replace the content shown in $headings with echo($rsRecordset->getColumnVal("ChapterText")); but my syntax must be wrong as it doesn't display anything. Can you help?