das Problem: mit PHP anfügen, wie füge ich die Abfrage Daten, die ich aus der Datenbanktabelle in die Konfigurationsdatei an verschiedene spezifische Positionen.mit php wie schreibe ich einen Code, der die Abfrage Daten in eine Datei an verschiedenen Positionen aus der Datenbanktabelle
die Datei, die
$filename = 'C:\wamp\www\disable_user\configurations\config_2';
$fp = fopen($filename, 'r+');
$sql="SELECT link FROM garden where id ='1' ";
if ($result= (mysqli_query($con,$sql)))
{
Fetch ein und eine Reihe
while($row=mysqli_fetch_row($result))
{
$replacement = $row[0];
$specific_line = 10; // sample value squeeze it on this line
//echo $specific_line;
//treat file as an array here.
$contents = file('C:\wamp\www\disable_user\configurations\config_2', FILE_IGNORE_NEW_LINES);
if($specific_line > sizeof($contents))
{
$specific_line = sizeof($contents) + 1;
//////echo $specific_line;
}
// Remove a portion of the array and replace it with something else
//array_splice($input , int $offset ,$length, $replacement = array()) how to splice an array
//array_splice($contents, $specific_line, 0, array($replacement));
//array_splice($contents, $specific_line-1, -1, array($contents[$specific_line-1].$replacement));
array_splice($contents, $specific_line-1, 1, array($contents[$specific_line-1].",".$replacement.","));//arrays start at zero index
$contents = implode("\n", $contents);
//echo $contents;
//writes a string to a file
file_put_contents('C:\wamp\www\disable_user\configurations\config_2', $contents);
echo "changes done";
}