php file_put_content覆盖

时间:2016-04-03 18:03:04

标签: php mysql

所以我发现这个代码可以写入特定的行

  function SetSiteName(){
        global $session, $database, $form;
    $filepathname = "include/classes/constants.php";
    $target = 'sitename';
    $newline = 'define("sitename", "Testing.");';

    $stats = file($filepathname, FILE_IGNORE_NEW_LINES);   
    $offset = array_search($target,$stats) +32;
    array_splice($stats, $offset, 0, $newline);   
    file_put_contents($filepathname, join("\n", $stats)); 
    header("Location: ".$session->referrer);
   }

然而,它不会覆盖该行的内容,它会转到下一行并将数据放入..我想让它覆盖当前在该行上的内容?

有什么想法?

1 个答案:

答案 0 :(得分:0)

您可以使用此代码覆盖文件的一行。

BO3->Prestige->Offset