• 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

Get WooCommerce products from specific category

PHP password_verify

Combine array with same value and add other [duplicate]

Query Optimization, changing the queries in the loop into a single processing query

Convert regular text to array using notepad++

Symfony autowiring issues since docker update

Fatal error: Array callback has to contain indices 0 and 1

how to hide previous markers when new markers added in google map javascript api

PHPMyAdmin not working as intended at remote server. Error 500, $respond not found

How avoid Moved Permanently The document has moved here

Error when uploading certain .png files "Interlace handling should be turned on when using png_read_image"

Could not decode a text frame as UTF-8.

How to get transaction details in notify_url page in paypal

Natural ORDER in Laravel Eloquent ORM

How to use PHPCBF to fix one issue at a time?

About Contact Privacy policy Terms and conditions