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