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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.