title: Bold some words in a string and remove some unbold words
body: <p>I am creating a search engine. Currently, my script bolds the matching words from the keyword. But some keywords are too long, like the results for <strong>shah rukh khan</strong>:</p>
  
  <blockquote>
    <p>25216d1235653089 <strong>shahrukh khan</strong> s
    wallpaper <strong>shah rukh</strong> actor</p>
  </blockquote>
  
  <p>As you see, the above keyword is too long. So, I need it to be like:</p>
  
  <blockquote>
    <p><strong>shahrukh khan</strong> s wallpaper </p>
  </blockquote>
  
  <p>or</p>
  
  <blockquote>
    <p><strong>shah rukh</strong> actor</p>
  </blockquote>
  
  <hr>
  
  <p>Currently, I am using the following code, but it requires a space before and after the bold tags. So, if the 1st word is bold, it displays the whole keyword.</p>
  
  <pre><code>if(strlen($img_keyword)&gt;30){
      $img_keyword = preg_replace('/(.*?) &lt;b&gt;(.*?)&lt;\/b&gt; (.*?)/us',
        " &lt;b&gt;$2&lt;/b&gt; ",
        $img_keyword);
  }
  </code></pre>
  
  <p>Is there a way to do/fix this?</p>