Check out my twitter script by CMXads
Goth and Gore Gifts Shop right now or else! | Sell your soul Believeth in me an hath everlasting life | Evil gear Christmas is almost here | PHP Gallery PHP Gallery is a free php image script. |
here are some of the best and useful php scripts and snippets to help in your projects. Php displayed below. Use the search for specific script lookups. Click the category links to view scripts in Javascript and cgi. To add your own script click the link and add your useful script example.
search field replace update delimited csv file line field values by field value
update file replace line csv flatfile field
<?php
function replace_line($file,$replace_array,$field_num,$field_val,$delimiter=';'){
if(isset($file,$replace_array,$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);
foreach($array as $k=>$v) {
$v=trim($v);
$add_arr .=$v.$delimiter;}//add just value and delimiter
$add_arr .="\n";
for ( $i = 0; $i < $rows; $i++ ){
$field = explode($delimiter, trim($contents[$i]));
if($field_val== $field[$field_num]) {
$contents[$i] = substr($add_arr,0,-1)."\n";//pop off trailing delimiter add newline
}}
$filerep = implode("", $contents);
$filerep = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $filerep);
if(file_put_contents($file,$filerep,LOCK_EX)){
return true;
}}}
$file='cart-data.txt';
//right from post array we dont add the key to file
//filter your input as you wishh first use array map
$arrin = array ("TARGET"=>'some string', "DESCRIP"=>"fields write test", "CONTENT"=>"content add row test 2");
//file - replace array in - numeric field index to target - field value to match
replace_line($file, $arrin, '4', 'string to match');
?>