2014-03-13 33 views

回答

2

使用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; 
+0

替代地,可以使用'$标签=阵列( '[a_tag]'= >'替换标签','[another_tag]'=>'替换另一个标签'); str_replace(array_keys($ tags),array_values($ tags),$ string);' –