Sterge in fisier linie care contine cuvant din baza de date
Scris: Sâm Mai 28, 2016
Salut, se poate cauta intr-un fisier un nume dintr-o baza de date ? Iar daca il gaseste sa stearga linia respectiva
Cursuri online, tutoriale, jocuri si anime - gratuite
https://marplo.net/forum/
Cod: Selectaţi tot
//returns True if the $word exists in $str, otherwise, False
function containsWord($str, $word){
return !!preg_match('#\b' . preg_quote($word, '#') . '\b#i', $str);
}
$str ='String to test if the word "check" exists in this string';
$word ='Check';
if(containsWord($str, $word)) echo 'word found';
else echo 'word not in string';
Cod: Selectaţi tot
$str = file_get_contents('adresa/fisier.ext');
Cod: Selectaţi tot
DELETE FROM nume_tabel WHERE id = $id
Cod: Selectaţi tot
$file_r ='file_read.txt'; //address of file to read
$file_s ='file_save.txt'; //address of file to save after delete the lines (can be the same $file_r)
$del_w ='word'; //word by which to delete the lines
//get the $file_r content into an array, by lines
$data_r = file($file_r, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$nrl = count($data_r); //number of lines
//traverses the lines and store in $data_s the lines without $del_w
$data_s =[];
for($i=0; $i<$nrl; $i++){
if(!preg_match('#\b' . preg_quote($del_w, '#') . '\b#i', $data_r[$i])) $data_s[] = $data_r[$i];
}
//saves the lines in $file_s
if(file_put_contents($file_s, implode(PHP_EOL, $data_s))) echo 'Content saved';
else echo 'Unable to save data in: '. $file_s;