Regular Expressions
The only thing you are missing is a delimiter in your regexp pattern. I believe this can be any character; a common choice is a forward slash. But then of course you must escape your existing forward slashes. Here are two examples, using forward slash and right square bracket.
$text = preg_replace('/<br \/>/', '</strong><br />', nl2br($text), 1);
$text = preg_replace(']<br />]', '</strong><br />', nl2br($text), 1);
Alternative
I agree with michaeljdennis that you should use str_replace
in this case. preg_replace
is appropriate for fancy replacements, but not one as simple as this.
However, str_replace
does not have a $limit argument. If you wish to limit the number of replacements to the first instance, do something like
// Split the string into two pieces, before and after the first <br />
$str_parts = explode('<br />', $row['message'], 2);
// Append the closing strong tag to the first piece
$str_parts[0] .= '</strong>';
// Glue the pieces back together with the <br /> tag
$row['message'] = implode('<br />', $str_parts);
...`), and the Accept button on your previous questions. – Niet the Dark Absol Nov 16 '11 at 01:15
to new line between pre tag](http://stackoverflow.com/questions/3028322/replace-br-to-new-line-between-pre-tag) (Remember: You can always find a better answer if you try the search function yourself!) – mario Nov 16 '11 at 01:18