• 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

Why the name of trucks are same in 2nd and 3rd record of company data retrieval?

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

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

Transpose multidimensional array and join values with commas

Shortcode or PHP inside a shortcode in Wordpress

PHPS source file - 403 Forbidden You don't have permission to access this resource

Lexik JWT authentication problem "Invalid credentials"

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

PHP Discord OAUTH2 code sample not working

Declaration of OMDb::query(string $statement) must be compatible with PDO::query

PHP Fatal error: Class not found - PHPUnit

If action is on a different page do I use fwrite function

Mysqli multi query error

CodeIgniter force_download is not working

Transpose and flatten multiple rows of array data [duplicate]

About Contact Privacy policy Terms and conditions