• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Read users and passwords from a txt file

phpfilefile-io


PHP Snippet 1:

$lines = file('file.txt');
$credentials = array();

foreach($lines as $line) {
    if(empty($line)) continue;

    // whole line
    $line = trim(str_replace(": ", ':', $line));
    $lineArr = explode(' ', $line);

    // username only
    $username = explode(':', $lineArr[0]);
    $username = array_pop($username);

    // password
    $password = explode(':', $lineArr[1]);
    $password = array_pop($password);

    // putting them together
    $credentials[$username] = $password;
}

print_r($credentials);

Related Snippets

How to convert a carbon into string, to take the date only?

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

How can I get new CSRF token in LARAVEL by using ajax

I cannot create a auto generated date time in mysql workbench

php script to delete files older than 24 hrs, deletes all files

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

How to display table header in every page using FPDF library?

php script to delete files older than 24 hrs, deletes all files

Create tags in laravel post publishing

Debugging Stripe Webhook Event

PHP and WebView - Cookie doesn't are the same

Lexik JWT authentication problem "Invalid credentials"

How to pass security cloudflare server with php curl

Laravel after login Two factor not working

Xdebug 3 not showing in phpinfo on m1 Monterey

About Contact Privacy policy Terms and conditions