PHP 中相同变量的不同位置的串联

Concatenation of different positions of the same variable in PHP

我在 php 代码中遇到了麻烦,问题是我想从变量 Cell old 显示变量 Cell new

$Cell old = ARI_0089_sect2

$Cell new = ARI_0089_h2(将 'sect' 替换为 'h' )

我发现的所有示例都连接了两个不同的变量,例如名字和姓氏

我没有找到如何连接同一变量的不同位置,这在 Microsoft excel 中是可能的,但我没有找到如何用 php 代码解决它。

$Cell new = str_replace('sect','h',$Cell old);

echo $Cell new;

尝试PHP函数str_replace

$Cell_old = "ARI_0089_sect2";
$new = str_replace('sect', 'h', $Cell_old);
echo $new;