I want to replace the word "Dozenten" with "Dozentin" and the word "Dozent" with "Dozenten" using PHP. The problem is, "Dozent" appears in both words. I can't continue using `str_replace`. How to avoid getting results similar to "Dozentenin"?
P粉2657249302023-07-18 14:14:29
你可以使用`strtr`函数来实现,它可以在字符串中进行子字符串的翻译(替换):
<?php
$s = "Dozenten Dozent Dozent Dozenten";
echo strtr($s, array("Dozenten" > "Dozentin", "Dozent" => "Dozenten"));