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/field-search-delete-file-line-function.txt: 880 bytes
delete file line search delimited csv field value
delete file line csv field value
<?php
func
tion delete_line($file,$field_num,$field_val,$delimiter=';'){
if(isset($file,$field_num,$field
_val)){
$f = fopen($file . '.lock', 'w');
flock($f, LOCK_SH);
$contents = file($file)
;
flock($f, LOCK_UN);
fclose($f);
$rows = count($contents);
for ( $i = 0; $i <
$rows; $i++ ){
$field = explode($delimiter, trim($contents[$i]));
if($field_val== $field[$fiel
d_num]) {
unset($contents[$i]);
}}
$filerep = implode("", $contents);
$filer
ep = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $filerep);
if(file_put_content
s($file,$filerep,LOCK_EX)){
return true;
}}}
$file='cart-data.txt';
// file - colum
n index number - column value
delete_line($file, '4', 'string to match');
?>
Post a comment
No comments yet