The following code generates a new php file playlist.php which contains the code as in $start $result variable
$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";
$inF = fopen($Fnm,"w");
fwrite($inF,$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";
fwrite($inF,$result);
}
}
fwrite($inF,"</asx>");
closedir($folder);
fclose($inF);
I want to generate the same code in the same file which contains this code on a specified line number
is this possible ?
The above php script generates the following code on a new file
http://tinypaste.com/ff242cd6
Here’s how to append:
That should do it…
EDIT:
Okay, before I get into it, you should first take a look at some basic PHP tutorials which can be found all over the net.
SO, instead of writing the content to the file, just echo it, and add your dynamic stuff while you echo:
I created a new variable called
$title. The value of that will be the title generated in the output. You can do this with other tags too like you’ve done with<entry>\n<title>$file</title>.