Check out my twitter script by CMXads
Till death do us part Axels New Music releases | Viking gear Gear Gifts and Apparel | Sharp Stuff Switchblades Icepicks and german knives | Evil gear Christmas is almost here |
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.
delete a file line using preg match to target exact match in line string
delete file line string preg match
<?php
function delete_line_preg($file,$target){
if(isset($file,$target)){
$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++){
if(preg_match('/\b' . $target . '\b/i', $contents[$i])){
unset($contents[$i]);
}}
$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';
// file - column index number - column value
delete_line_preg($file, 'target string');
?>