stickman Posted August 29, 2006 Share Posted August 29, 2006 I have this code for my search:[code]<?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;?>[/code]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 >? Link to comment https://forums.phpfreaks.com/topic/19075-removed-nested-bolds/ Share on other sites More sharing options...
stickman Posted August 30, 2006 Author Share Posted August 30, 2006 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 >". Link to comment https://forums.phpfreaks.com/topic/19075-removed-nested-bolds/#findComment-83134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.