Php 通过wordpress筛选器更改内容中的多个单词

Php 通过wordpress筛选器更改内容中的多个单词,php,wordpress,filter,Php,Wordpress,Filter,我使用wordpressfilter通过下面的代码更改内容中的许多单词 function upperworld ($content){ $string1 = array('1' => 'BA YEU CON', '2' => 'CON YEU ME' ); $string = array('1' => 'abc', '2' => 'ccb' ); foreach ($string as $key => $thay) { f

我使用
wordpress
filter通过下面的代码更改内容中的许多单词

function upperworld ($content){

    $string1 = array('1' => 'BA YEU CON', '2' => 'CON YEU ME' );
    $string = array('1' => 'abc', '2' => 'ccb' );

    foreach ($string as $key => $thay) {
        foreach ($string1 as $key => $canthay) {
            $content = str_replace($thay, $canthay, $content)
        }
    }
    return $content;
}
add_filter( 'the_content', 'upperworld' );

它不工作,请帮助我修复它。

只需尝试下面的代码来更改内容()中的单词。


您错过了
$content=str_replace($thay,$canthay,$content)语句中的code>

通过以下方式更新您的代码

foreach ($string as $key => $thay) {
    foreach ($string1 as $key => $canthay) {
        $content = str_replace($thay, $canthay, $content);
    }
}


你能写下你得到的是什么问题吗?好的,很好,你能接受这个答案吗。。如果对你有用的话。
foreach ($string as $key => $thay) {
    foreach ($string1 as $key => $canthay) {
        $content = str_replace($thay, $canthay, $content);
    }
}
$content = preg_replace(array_map(function($row){return "/{$row}/";}, $string), $string1, $content);