Reputation: 1228
Using PHP, how would I convert an HTML string say, '+text+'
to '<em>text</em>'
so that if a user types +text+ in an input, it outputs as text?
Upvotes: 0
Views: 41
Reputation: 4741
if all you want to do is use you can do.
$input = "+text+";
$input = trim($input, '+');
$input = '<em>' . $input . '</em>';
Upvotes: 0
Reputation: 3461
You can use str_replace along side explode or regex
$text_string = '+TEST+';
$text = explode("+", $text_string);
$text = $text[1];
$replaced_text = str_replace("+$text+", "<em>$text</em>", $text_string);
echo $replaced_text; // output: <em>TEST</em>
Upvotes: 2