Php Wordpress使用str_替换

Php Wordpress使用str_替换,php,wordpress,str-replace,Php,Wordpress,Str Replace,如何使用functions.php中的str_replace替换现有标记的内容 例如,DOM显示 <h1> smth </h1> smth 我想把它改成 <h2> smth else </h2> smth-else $newString=str_replace('h1','h2','smth'); $newString=str_replace('smth','smth else',$newString); $newString = str

如何使用functions.php中的str_replace替换现有标记的内容

例如,DOM显示

<h1> smth </h1>
smth
我想把它改成

<h2> smth else </h2>
smth-else
$newString=str_replace('h1','h2','smth');
$newString=str_replace('smth','smth else',$newString);

$newString = str_replace('h1', 'h2', '<h1> smth </h1>');
$newString = str_replace('smth', 'smth else', $newString);