【问题标题】:php append on a specific linephp 追加到特定的行
【发布时间】:2012-07-27 05:13:58
【问题描述】:

以下脚本将代码附加到同一文件的末尾

$path = "./files/";
$path2="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/";
//echo $path2;
$folder = opendir($path);
$start="<asx version='3.0'>\n<title>Example ASX playlist</title>";
$Fnm = "./playlist.php";
// build content
$fileContent=$start.'/n';

while( $file = readdir($folder) ) {
 if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
 $result="<entry>\n<title>$file</title>\n<ref href='$path2$file'/>\n<param name='image'        value='preview.jpg'/>\n</entry>\n";
 //append to content
$fileContent .= $result;
}
}
 //append to content
$fileContent .= "</asx>";

// append to file and check status
if ( file_put_contents(__FILE__ , $fileContent , FILE_APPEND) === false )
{

echo "failed to put contents in ".__FILE__."<br>";

}

我想将此附加到特定行,例如第 12 行

这个append的结果如下

{
levels: [
{ file: "/bkaovAYt-3647661.mp4" },
{ file: "/bkaovAYt-3647661.mp4" }
],
title: "bkaovAYt-3647661.mp4"
},

这可能吗?

【问题讨论】:

    标签: php append


    【解决方案1】:

    您可以将第二组代码放在一个文件中,例如 include.php,然后使用以下代码将其放在 PHP 主代码中您想要的任何位置:

    include("include.php");
    

    【讨论】:

    • 我可以在 javascript 之间使用这个包含吗? 之间的示例
    • 当然。它实际上将代码放在include() 所在的位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2018-07-04
    • 2019-01-15
    • 1970-01-01
    • 2016-03-29
    • 2013-05-21
    相关资源
    最近更新 更多