我使用wordpress
过滤器通过此代码更改内容中的多个单词
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' );
它不起作用,请帮我解决它
答案 0 :(得分:0)
只需尝试以下代码即可更改the_content()
function upperworld ($content){
$string1 = array('1' => 'BA YEU CON', '2' => 'CON YEU ME' );
$string = array('1' => 'abc', '2' => 'ccb' );
foreach ($string1 as $key => $canthay) {
$thay = $string[$key];
$content = str_replace($thay, $canthay, $content);
}
return $content;
}
add_filter( 'the_content', 'upperworld' );
答案 1 :(得分:0)
您错过了;
$content = str_replace($thay, $canthay, $content);
通过此
更新您的代码foreach ($string as $key => $thay) {
foreach ($string1 as $key => $canthay) {
$content = str_replace($thay, $canthay, $content);
}
}
OR
$content = preg_replace(array_map(function($row){return "/{$row}/";}, $string), $string1, $content);