Reputation: 59
I want to use strstr(), to delete everything before a word. I already have this here:
$file = file_get_contents('text.txt');
$deleted = strstr($file, 'word');
echo $deleted;
But this, is only for one line! I need, to delete everything before a word on every single line in my txt file.
I hope someone can help me :)
Upvotes: 1
Views: 274
Reputation: 59681
This should work for you:
(Her I just get all lines into a array with file()
. Then I go through each element with array_map()
and remove everything before "word" with strstr()
)
$file = file('text.txt');
$deleted = array_map(function($line){
return strstr($line, "word");
}, $file);
echo implode("<br />", $deleted);
Example file:
test word test2
test word test
Output:
word test2
word test
Upvotes: 1