Crude outside-the-box work-around...

You are only looking for <div and </div and what's between them, right?

Playing with strpos and a simple stack for nested DIVs should let you
hack this in a crude parser:

<?php
//Untested code, off the top of my head:
$divs = array();
$stack = array();
$offset = 0;
$len = strlen($html);
while($offset < $len){
  $divpos = strpos($html, '<div', $offset);
  $endpos = strpos($html, '</div', $offset);
  if ($divpos === false && $endpos === false) break;
  if ($divpos !== false && $divpos < $endpos){
    array_push($stack, array($offset, $divpos));
    $offset = $divpos + 1;
  }
  else{
    $start = array_pop($stack);
    $divs = array($start, array($offset, $endpos));
    $offset = $endpos + 1;
  }
}
var_dump($divs);
?>

This should give you offsets to the beginning/end of each DIV tag.

I'm sure I've got a one-off error or I'm not tracking quite the right
numbers, or that I'm tracking extra numbers you don't need, but the
idea is sound.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to