PHPで文字列置換はstr_replace

// <body text='black'> となります
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");