Also, ich will die Datei "test.php" einlesen, dann darin ">" mit "?>" ersetzen und dann die Datei mit dem neuen Inhalt ersetzen... Also aus
<?php echo "test"; >
wird
<?php echo "test"; ?>
Mein Ansatz momentan:
<?php function stri_replace($find,$replace,$string) { if(!is_array($find)) $find = array($find); if(!is_array($replace)) { if(!is_array($find)) $replace = array($replace); else { // this will duplicate the string into an array the size of $find $c = count($find); $rString = $replace; unset($replace); for ($i = 0; $i < $c; $i++) { $replace[$i] = $rString; } } } foreach($find as $fKey => $fItem) { $between = explode(strtolower($fItem),strtolower($string)); $pos = 0; foreach($between as $bKey => $bItem) { $between[$bKey] = substr($string,$pos,strlen($bItem)); $pos += strlen($bItem) + strlen($fItem); } $string = implode($replace[$fKey],$between); } return($string); } $dz = fopen(test.php,"w"); $file = file(test.php); $fertig = stri_replace('>','?>',$file); fwrite ($dz,$fertig); fclose($dz); ?>
Warum geht das nicht? Der erstellt ne neue Datei namens "testphp" und schreibt "Array" da rein... :(
Bitte hilfe :)
Nachtrag:
Mit
$filename = "test.php"; $dz = fopen($filename,"a+"); $contents = fread ($dz, filesize ($filename)); $fertig = stri_replace('echo','becho',$contents); fwrite ($dz,$fertig); fclose($dz);
macht er in der test.php
aus:
<?php echo "test"; ?>
dieses
<?php echo "test"; ?><?php becho "test"; ?>
eventuell vor dem schreiben mit unlink() löschen und dann neu erstellen?!