Enter a search term check the script type and click submit. To search for a general category for example to find all results for scripts working with text files or file manipulation enter file or curl. Same for directory, sql etc. Otherwise use specific terms.
Here is the script you requested.
scripts/search-column-replace-value-update-file-line.txt: 657 bytes
easiest method to search a delimited file column and update a column
column value update delimited
file update replace value
<?php
$data = file_get_contents('./users.txt');
//double explode in one
shot
$users = array_map(function($line) {return explode(',', $line);}, explode("\n", $data));
forea
ch ( $users as $i => $user ) {
if ( $user[0] == $username ) {//search column 0 for username variab
le
$user[1] = $userpwd;//update column 1 with new value
$users[$i] = $user;//put back togeth
er
}
}
//implode in one shot and save
file_put_contents('./users.txt', implode("\n", array_map(fun
ction($line) {return implode(',', $line);}, $users)));
?>
Post a comment
No comments yet