PHP to search within txt file and echo the whole line

And a PHP example, multiple matching lines will be displayed: <?php $file=”somefile.txt”; $searchfor=”name”; // the following line prevents the browser from parsing this as HTML. header(‘Content-Type: text/plain’); // get the file contents, assuming the file to be readable (and exist) $contents = file_get_contents($file); // escape special characters in the query $pattern = preg_quote($searchfor, “https://stackoverflow.com/”); // … Read more

How to delete a line from a text file in C#?

For very large files I’d do something like this string tempFile = Path.GetTempFileName(); using(var sr = new StreamReader(“file.txt”)) using(var sw = new StreamWriter(tempFile)) { string line; while((line = sr.ReadLine()) != null) { if(line != “removeme”) sw.WriteLine(line); } } File.Delete(“file.txt”); File.Move(tempFile, “file.txt”); Update I originally wrote this back in 2009 and I thought it might be … Read more

How do I correct the character encoding of a file?

Follow these steps with Notepad++ 1- Copy the original text 2- In Notepad++, open new file, change Encoding -> pick an encoding you think the original text follows. Try as well the encoding “ANSI” as sometimes Unicode files are read as ANSI by certain programs 3- Paste 4- Then to convert to Unicode by going … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)