Jump to content

i need help with a script


jet8791

Recommended Posts

I have a script here that i been working on and i cant get it right yet. can anybody help me. what i want it to do is open a folder called "files" open every txt file in the folder and go the 5th "|" and set the value to "0".can anybody help me? here is the script
[code]
    <?php

    $dirname = "./files";
    $dh = opendir( $dirname ) or die("couldn't open directory");
    while ( $file = readdir( $dh ) ) {
    if ($file != '.' && $file != '..' && $file != ".htaccess") {
    $fh=fopen("./files/" . $file ,"w");
    foreach($fh as $fline)
    $fline = explode('|', fgets($fh));

    fputs($fh,$fline[0]."|". $fline[1]."|". $fline[2]."|". $fline[3]."|". $fline[4]."|".($fline[5]=0)."|". $fline[6]."|". $fline[7]."|". $fline[8]."|\n");
    }
    }
    fclose($fo);

    echo "ok!";

    ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/26278-i-need-help-with-a-script/
Share on other sites

try[code]<?php
$dirname = "./files";
$dh = opendir($dirname) or die("couldn't open directory");
while ($file = readdir($dh)) {
    if ($file != '.' && $file != '..' && $file != ".htaccess") {
    $fcon=file("$dirname/$file");
    $fh=fopen("$dirname/$file ", 'w');
    foreach ($fcon as $fline) {
    $fline = explode('|', $fline);
    $fline[5]=0;
    $fline = implode('|', $fline);
    fputs($fh, $fline);
    }
    fclose($fh);
    }
}
echo "ok!";
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.