我试图通过制作简单的文本编辑器来学习php。 所以我创建了一个应该替换文本文件字符串的类,但看起来它不起作用。如果你能帮助我,我会很高兴的。这是代码的一部分。
<?php
$classer = new editorCore();
$classer->transaction($_POST['oldString'],$_POST['newString']);
class editorCore{
public $oldString;
public $newString;
function transaction($oldString,$newString){
if(isset($oldString)&&isset($newString)){
$this->oldString = $oldString;
$this->newString =$newString;
$classer = new editorCore();
$say =$classer->caller();
echo $say;
}else{
echo "There is an error";
}
}
function caller(){
$line = file('test.txt');
foreach($line as $li){
$rep = str_replace($this->oldString, $this->newString, $li);
}
//wanted to replace the string and display it to the html
$line = file('test.txt');
foreach($line as $li){
echo $li;
}
echo "<br />";
}
}
?>