When I replace something, it will just replace everything; That's okay. But what I would like to know is this:
str_replace("*", "<strong>", $message);
Is it possible to use str_replace() for codes like * This content is Bold *, just having the content, but still replacing the asterisks with <strong> and </strong>?
Example:
Original: **This Should be Bold**
After Replacing: <strong>This Should be Bold</strong>
Use regular expression instead; it's more convenient:
$message = "**This Should be Bold**";
$message = preg_replace('#\**([^\*]+)\**#m', '<strong>$1</strong>', $message);
echo $message;
Or if you want to limit the number of asteroids to 2:
'#\*{1,2}([^\*]+)\*{1,2}#m'
You can also do like this
https://eval.in/518881
<?php
$string = '**This Should be Bold**';
$string = preg_replace("/\*\*(.+?)\*\*/", "<strong>$1</strong>", $string);
echo $string;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With