0
我想在我的字符串中插入标签。可以稍后更换。例如,我们如何添加和替换php中的标签
$msg = "This message was sent [tag replaced later] at []";
有没有办法做到这一点。谢谢。
我想在我的字符串中插入标签。可以稍后更换。例如,我们如何添加和替换php中的标签
$msg = "This message was sent [tag replaced later] at []";
有没有办法做到这一点。谢谢。
使用str_replace函数..
$tags = array(
'[a_tag]',
'[another_tag]'
);
$replacements = array(
'replace a tag',
'replace another tag'
);
$string = 'I want to [a_tag] and [another_tag]';
$string = str_replace($tags, $replacements,$string);
echo $string;
替代地,可以使用'$标签=阵列( '[a_tag]'= >'替换标签','[another_tag]'=>'替换另一个标签'); str_replace(array_keys($ tags),array_values($ tags),$ string);' –
考查[str_replace函数(http://it2.php.net/str_replace) – tchow002