我想使用PHP将单词"Dozenten"替换为"Dozentin",将单词"Dozent"替换为"Dozenten"。问题是,"Dozent"在两个单词中都出现。我无法继续使用`str_replace`。如何避免得到类似于"Dozentenin"这样的结果呢?
你可以使用`strtr`函数来实现,它可以在字符串中进行子字符串的翻译(替换):
<?php $s = "Dozenten Dozent Dozent Dozenten"; echo strtr($s, array("Dozenten" > "Dozentin", "Dozent" => "Dozenten"));
你可以使用`strtr`函数来实现,它可以在字符串中进行子字符串的翻译(替换):
<?php $s = "Dozenten Dozent Dozent Dozenten"; echo strtr($s, array("Dozenten" > "Dozentin", "Dozent" => "Dozenten"));