• 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

Add and update products to session cart in Laravel

Add custom text under order details on WooCommerce My account view order pages

Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path: ) in Unknown on line 0

str_replace or preg_replace random number from string

Handling expired token in Laravel

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

PHP: How to raise number to (tiny) fractional exponent?

CONCAT columns with Laravel 5 eloquent

PHP Form Not Inserting

SQL AVG() to 2 decimals

PHP: Telegram Bot: Insert line break to text message

Hide specific products from unlogged users based in product category in WooCommerce

Get latest Tweets - What API

Combine array with same value and add other [duplicate]

How to check user Permissions using Custom Middleware in Laravel

About Contact Privacy policy Terms and conditions