Replace a whole line where a particular word is found in a text file

One approach that you can use on smaller files that can fit into your memory twice: $data = file(‘myfile’); // reads an array of lines function replace_a_line($data) { if (stristr($data, ‘certain word’)) { return “replacement line!\n”; } return $data; } $data = array_map(‘replace_a_line’, $data); file_put_contents(‘myfile’, $data); A quick note, PHP > 5.3.0 supports lambda functions … Read more

Haskell file reading

Not a bad start! The only thing to remember is that pure function application should use let instead of the binding <-. import System.IO import Control.Monad main = do let list = [] handle <- openFile “test.txt” ReadMode contents <- hGetContents handle let singlewords = words contents list = f singlewords print list hClose handle … Read more

Android Word-Wrap EditText text

Besides finding the source of the issue, I found the solution. If android:inputType is used, then textMultiLine must be used to enable multi-line support. Also, using inputType supersedes the code android:singleLine=”false”. If using inputType, then, to reiterate, textMultiLine must be used or the EditText object will only consist of one line, without word-wrapping. Edit: Thank … Read more

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