使用PHP,如何将HTML字符串'+text+'
转换为'<em>text</em>'
,以便如果用户在输入中键入+text+,则输出为text?
您可以使用str_replace沿边爆炸或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>
如果你只想使用你能做的。
$input = "+text+";
$input = trim($input, '+');
$input = '<em>' . $input . '</em>';