Jump to content

Removed nested bolds


stickman

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.