Jump to content

Archived

This topic is now archived and is closed to further replies.

stickman

Removed nested bolds

Recommended Posts

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 >?

Share this post


Link to post
Share on other sites
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 >".

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.