views:

101

answers:

1

Hello!

I have a page with multiple H1 headings followed by text and so on. Example:

<h1>Title 1</h1>Some text here
<h1>Title 2</h1>Some moretext here
<h1>Title 3</h1>Even more text here

etc

What I want to do is create an array of elements, that is explode the html using as separator <h1>ANY TEXT</h1> above that I have in an $output variable.

The final purpose is to count the strlen of the text between the ending </h1> and next starting <h1> and if it's higher than 200 characters to hide it inside a with display:none so users can press "Show all" to unhide that.

How can I get that please?

Thanks!

A: 

You could use the SimplePHPDom to do this before sending the page out to the client:

ob_start();
// build page here
$html = ob_get_clean();

$dom = str_get_html($html);

$headings = $dom->find('h1');

foreach($headings as $h1) {
   // process node to add CSS to hide node and change text to 'show more'
}

This could also be done client-side with jQuery/MooTools, with basically the same process (minus the buffering capture stuff).

Marc B
I think OP wants to analyze the text that comes **after** the H1 tags... `text between the ending </h1> and next starting <h1>`
Peter Ajtai
Ah yes... d'oh... Mondays... In that case, `$h1->nextSibling()` would probably come into play within the `foreach()`
Marc B