I'm currently using the following code to allow bolded posts on my forum:

$str = preg_replace('#&lt;b&gt;(.*?)&lt;/b&gt;#i', '<b>$1</b>', $str);

Which works fine, unless the bold tags span several lines.

For example:

<b>Test Test</b>

- Works Fine

<b>Test
Test</b>

- Does not work.

I'm at a loss as to what could be causing this, and at more of a loss as to how to fix it.

Any thoughts?

    Add an "s" to the pattern modifiers (along with the "i" modifier you already have) so that the "." wildcard includes newlines.

      PS: You might also want to add the "U" (ungreedy) modifier so that...

      &lt;b&gt;one&lt/b&gt; &lt;b&gt;two&lt/b&gt;
      

      ...does not become...

      <b>one&lt/b&gt; &lt;b&gt;two</b>
      

        Awesome, thanks a ton!

        I have one other regex question that you (or somebody else) may be able to help me with;

        I use the following regex to convert text links into clickable links:

        $text = preg_replace("#(http://[\s]+)#i", "<a href='\1' target='blank' >\1</a>",$text);
        $text = preg_replace("#(?<!(http://))(www.[\s]+)#i", "<a href='http://\2' target='
        blank' >http://\2</a>",$text);

        Is there a way to only convert it to a link if there is nothing preceeding the link?

        The reason behind this is because when I am posting raw HTML, it messes up things like image tags. ('<img src="www.google.com/image.gif" />' would turn into '<img src="<a href=www.google.com/image.gif>www.google.com/image.gif</a>" />' and obviously not work correctly.

        I've tried several things but nothing I've tried seems to work.

          Not sure if this is what you mean, but you could try a negative look-ahead assertion:

          <?php
          header("Content-Type: text/plain");
          $test = <<<EOD
          This is a www.site.net test.
          This is a www.store.co.uk test.
          www.beggining.of.line followed by www.endof.line.
          Here is a <a href="http://www.site.net">link</a> in an A tag.
          EOD;
          echo preg_replace('#(?<!//)www(\.[^.\s\n\r]+){2,3}\b#i', 
                            "<a href='$0'>$0</a>", $test);
          ?>
          
            Write a Reply...