Jump to content


Photo

Removed nested bolds


  • Please log in to reply
1 reply to this topic

#1 stickman

stickman
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 29 August 2006 - 10:59 PM

I have this code for my search:

<?php
$q_words = array("test", "te");
$title = "test";
$word_ary = array();
foreach($q_words as $q_word) {
	if(strtolower($q_word)=="b" || empty($q_word) || in_array($q_word,$word_ary)) {continue;}
	$word_ary[] = $q_word;
	$title = eregi_replace(quotemeta(stripslashes($q_word)), "<b>\\0</b>", $title);
}
while(preg_match('#<b>(.*?)<b>(.*?)</b>(.*?)</b>#',$title)) {
	$title = preg_replace('#<b>(.*?)<b>(.*?)</b>(.*?)</b>#',"<b>\\1\\2\\3</b>",$title);
}
echo $title;
?>

For the example $title I provided, that works perferctly, but if $title was "test test test", the output would be "<b>test</b> test <b>test</b>". So my question is, is there a way to remove nested <b > and </b >?

..:: FREE NINTENDO WII OR $250 CASH ::..
..:: Click here for more information ::..


#2 stickman

stickman
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 August 2006 - 09:17 PM

Maybe I should simplify my question. If I have "<b ><b >Te</b >st</b >", how do I make it "<b >Test</b >"? And it has to work with various different nested bold tags, for example: "<b ><b >Te<b >s</b ></b >t <b >Test</b ></b >" would become "<b >Test Test </b >".

..:: FREE NINTENDO WII OR $250 CASH ::..
..:: Click here for more information ::..





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users