10 GIG txt file - Need to delete info on every line

Joined
Jul 4, 2023
Messages
507
Reaction score
63
I also agree with Ragnar28 that the best way to solve this issue is to use RegEx, but you might also consider using e.g. file and
array_map.
.

e.g [ on-line ]

10gig-test.txt
Code:
xxxxx eqweqwe www.google.com xxxxx qweqweqweqw
xxxxxxx eqweqweaaaaa www.lorem.com/lorem/ xxxxxxx qweqweqweqw
xxxxx eqweqwe www.lorem.ipsum.com/index?l=lorem yyyyyyy qweqweqweqw
xxxxx eqweqwe www.google.com xxxxx qweqweqweqw

xxxxx eqweqwe www.google.com xxxxx qweqweqweqw


xxxxx eqweqwe www.ipsum.com xxxxx qweqweqweqw
xxxxx eqweqwe www.ipsum.com/lorem-lorem-ipsum xxxxx yyyyyyyyy qweqweqweqw

PHP:
    $file = file('10gig-test.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $file = array_map(function($line) { return explode(' ', substr($line, strpos($line, 'www')))[0] . PHP_EOL; }, $file);
    file_put_contents('10gig-test_clean.txt',  $file);

    // only for demonstration purpose
    var_dump(array_map(function($line) { return trim($line, PHP_EOL); }, $file));
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top