2014-03-13 74 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);' –