我想替换文件中的字符串,这里的问题是字符串中存在非常类似的字符串。 有一个字符串“[100]”,然后是“[101]”等。 我想只替换括号内部,然后将其返回给文件。使用PHP和HTML替换文件中的字符串
问题是变量保持空着,我的Str_replace不做任何事情。 任何人都知道我在哪里去了?
这些是我的变量和替换字符串,我从另一个.html文件中获取。它读取文件并给出括号中字符串的所有条目。现在我想改变他们klicking他们
<table style="padding-top:10px" align=center>
<tr>
<td rowspan = "6">
<table>
<?php include("./sip_table.php"); foreach($dw as $row):?>
<tr>
<?php foreach($row as $k=>$cell):?>
<td><?php include("./fill.php"); echo "<button id=\"{$cell}\" onclick=\"ausfüllen('{$cell}','{$name}','{$nummer}','{$pw}')\">{$cell}</button>"; ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table></td> </tr>
<tr>
<td>
<table>
<tr> <td> Durchwahl </td> <td> <input type="text" id="nv_durchwahl" name="nv_dw" value=""></td> </tr>
<tr> <td> Anzeigename </td> <td> <input type="text" id="nv_anzeigename" name="nv_ane" value=""></td> </tr>
<tr> <td> Angezeigte Durchwahl </td> <td> <input type="text" id="nv_anzeigenummer" name="nv_anm" value=""> </td> </tr>
<tr> <td> Passwort </td> <td> <input type="text" id="nv_passwort" name="nv_pw" value=""> </td> </tr>
<tr><td><br/></td><td><br/></td></tr>
<tr>
<td><input type="submit" id="nv_speichern" name="nv_speichern" value="Speichern"></td>
<td><input type="submit" id="nv_delete" name="nv_delete" value="Löschen"> </td>
<td> <input type="submit" id="nv_add" name="nv_add" value="Hinzufügen"> </td></tr>
</table>
</td>
</tr>
</table>
这是我更换.PHP脚本:
<?php
$file = '/etc/asterisk/sip_dev.conf';
$content = file_get_contents($file);
//Replace Durchwahl
$content = str_replace('[{$_SESSION["dw"]}]', '[{$_GET["nv_durchwahl"]}]', $content);
//Replace Name & Anzeigenummer
$content = str_replace('callerid={$_SESSION["name"]} <{$_SESSION["nummer"]}>', 'callerid={$_GET["nv_anzeigename"]} <{$_GET["nv_anzeigenummer"]}>', $content);
//Replace Passwd
$content = str_replace('secret={$_SESSION["pw"]}', 'secret={$_GET["nv_passwort"]}', $content);
file_put_contents($file, $content);
?>
的脚本来填补editform是:
<script>
function ausfüllen(dw, name, nummer, pw) {
document.getElementById("nv_durchwahl").value = dw;
document.getElementById("nv_anzeigename").value = name;
document.getElementById("nv_anzeigenummer").value = nummer;
document.getElementById("nv_passwort").value = pw;
}
</script>
究竟是什么问题?你也应该发布javascript。 – jeroen
是的,对不起。我编辑它并发布我的Editform和脚本。 它没有做任何事情,我的变量保持空白(如果我在其他.php文件中访问它们) – VitaminAqua