here we go, rather messy but it does the job of returning the character locations of designated tags within a string.
Called with the two lines below. 1 to set up which tags we want to search for, 2nd is the call from within the class.
$badtags=array('<b','</b','<i','</i','<P','</p','<STRONG','</STRONG','<EM','</EM','<U','</U','<FONT','</FONT','<OL','</OL','<LI','</LI','<A','</A','<BLOCKQUOTE','</BLOCKQUOTE','<HR');
$nogo_locations=$this->stripos_words($thetext,$badtags);
The function
function stripos_words($haystack,$needles_array,$pos_as_key=true)
{
for ($iz=0;$iz<sizeof($needles_array);$iz++)
{
$needles=$needles_array[$iz];
$idx=0; // Used if pos_as_key is false
// Convert full text to lower case to make this case insensitive
$haystack = strtolower($haystack);
// Split keywords and lowercase them
$needle=strtolower($needles);
// Get all occurences of this keyword
$i=0; $pos_cur=0; $pos_found=0;
while ( $pos_found !== false )
{
// Get the strpos of this keyword (if thereis one)
$pos_found = strpos(substr($haystack,$pos_cur),$needle);
if ( $pos_found !== false )
{
// Set up key for main array
$index = $pos_as_key ? $pos_found+$pos_cur : $idx++;
// Populate main array with this keywords positional data
$positions[$index]['start'] = $pos_found+$pos_cur;
$pos_cur += ($pos_found+strlen($needle));
$positions[$index]['endish'] = $pos_cur;
// find the close of the >
$pos_cur = strpos($haystack, '>', $pos_cur);
$positions[$index]['end'] = $pos_cur;
//
$positions[$index]['word'] = $needle;
$i++;
$thebadchars[]=$positions[$index]['start'];
$num=$positions[$index]['start'];
// create a new array filling in the gaps between the starts and ends of the tag
while($num!=$positions[$index]['end'])
{
$num+=1;
$thebadchars[]=$num;
}
}
}
}
// If we found anything then sort the array and return it
if ( isset($positions) )
{
sort($thebadchars);
return $thebadchars;
}
// If nothign was found then return false
return false;
}
The only issue with it currently is it falls over on things like or similar. It will be a simple fix to get sort that out i think.
ta,
Hugh