Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php...zeile in textdatei überschreiben...

Empfohlene Antworten

Veröffentlicht

hi,

will ein kleines script für eine log datei schreiben.

format:

Zahl:IP:Host

das untenstehende funktioniert auch so weit. ich hab nur das problem, dass wenn der alte eintrag länger ist als der neue immernoch ein rest des alten eintrags zu sehen ist.

alter eintrag:

1:1.2.3.4:alter.host

neuer eintrag:

2:6.7.8.9:neu.host

ergebnis:

2:6.7.8.9:neu.hostst

der neue eintrag soll die alte zeile aber komplett löschen. was kann ich tun???

cu TinTin


<?

$path = "./log/";
$file = "test.log";

if (file_exists($path.$file))
{
$logCount = fopen($path.$file, "r+");
if ($logCount)
{
$readLog = fgets($logCount,1000);
$li = strstr($readLog, ":");
if ($li)
{
list ($isCount, $lastIp, $lastHost) = split (':', $readLog);

ftruncate ($logCount, ftell($logCount));

$newCount = ($isCount+1);
$newIp = $REMOTE_ADDR;
$newHost = gethostbyaddr($senderIp);
$newEntry = $newCount.":".$newIp.":".$newHost;
}


// dateizeiger zurücksetzen
rewind($logCount);
// rausschreiben
flock($logCount,2);
fwrite($logCount, $newEntry);
flock($logCount,3);
// dateizeiger schließen
fclose($logCount);
exit;
}
else
{
echo "2. Datei wurde nicht gefunden ".$file;
exit();
}

print $newEntry;
?>[/PHP]

ich würde die datei komplett einlesen (array file ($filename) )

dann den array nach dem alten eintrag durchsuchen und diesen dann z.B. mit preg_replace mit dem neuen ersetzen

dann haste ein array mit der aktualisierten logdatei und diesen schreibst dann einfach auf die datei

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.