Javascript 用php进行数据处理
我是新来php的,我一直在sin saber那里,你去看看你是否能给我一个想法。 情况如下: 我正在读一个网站并在上面写下:Javascript 用php进行数据处理,javascript,php,Javascript,Php,我是新来php的,我一直在sin saber那里,你去看看你是否能给我一个想法。 情况如下: 我正在读一个网站并在上面写下: <?php $ archivo ="prueba.html"; $ abrir= fopen($archivo,"r"); $ contenido = fread($abrir, filesize($archivo)); fclose($abrir); if (isset($ _ POST['input2'])) { $ Output = $ _ POS
<?php
$ archivo ="prueba.html";
$ abrir= fopen($archivo,"r");
$ contenido = fread($abrir, filesize($archivo));
fclose($abrir);
if (isset($ _ POST['input2'])) {
$ Output = $ _ POST['input2'];
$ archivo = fopen("prueba.html", "w");
fputs($archivo);
$ archivo ="prueba.html";
$ abrir = fopen($archivo, "r");
$ contenido = file_get_contents($archivo);
fclose($abrir);
}
?>
现在我有了网站所有数据的可变内容
如何访问可变内容的内容修改网站的段落或标题我认为您应该使用正则表达式来实现这一点: 查找内容并显示示例:
preg_match("/(<tag>)(.*)(<\/tag>)/", $input_line, $output_array);
这是一个用php检查正则表达式的好网站:
现在,让我们一起抓住它:
编辑新内容的表单页面:
<?php
$input_line = getMyFileContents();
preg_match("/(<tag>)(.*)(<\/tag>)/", $input_line, $output_array);
$oldContent = $output_array[2];
?>
<form action="action_page.php" id="usrform">
<input type="submit">
</form>
<br>
<textarea rows="4" cols="50" name="newContent" form="usrform">
<?php echo $oldContent; ?>
</textarea>
更改数据的“action_page.php”:
<?php
/* get new content from the posted form */
$newContent = $_REQUEST["newContent"];
$newContent = "new_tag_content";
$input_lines = getMyFileContents();
/* change the content */
preg_replace("/(<tag>)(.*)(<\/tag>)/", "$1" . $newContent . "$3", $input_lines);
/* write $input_lines to your file */
functionToChangeYourFileContents($input_lines);
不要在$
和变量名之间留空格。fputs()
需要两个参数——你在向文件中写入什么?@Barmar:它不能工作:解析错误:语法错误,意外的'foo'(t_字符串),预期变量(t_变量)或'$'
对于$foo='bar';echo$foo代码>哦,我只是假设它能工作,因为他没有说他有错误。请原谅我翻译的错误。我需要的是尝试更改div或段落的内容,或者更改图像,我在变量内容中有每个数据页,但它不知道如何处理该变量
<?php
/* get new content from the posted form */
$newContent = $_REQUEST["newContent"];
$newContent = "new_tag_content";
$input_lines = getMyFileContents();
/* change the content */
preg_replace("/(<tag>)(.*)(<\/tag>)/", "$1" . $newContent . "$3", $input_lines);
/* write $input_lines to your file */
functionToChangeYourFileContents($input_lines);