如何更换这个?

How to replace this?

出于编码目的,我想将输入标签的名称替换为另一个名称。这是我在输入标签中的默认文本:

<input type="text" name="def" id="def">

我想成为def = defense

我想这样做的原因是因为我设计了 def 用于在 php 上编码,我想 echo defense not as def(因为他们会知道什么我输入了 php 个脚本。

你可以在这里使用preg_replace,我知道这不是最好的方法,但你的目的会达到。

$str = '<input type="text" name="def" id="def">';
$str = preg_replace('/name="def"/', 'name="defense"', $str);