• 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 assert parameter attribute sub-structures in PHPUnit mock call expectations

Woocommerce redirect after add-to-cart error

Nginx disallowing execution of PHP in uploads directory with Magento

Codeigniter, Severity: error --> Exception: Too few arguments to function, admin dashboard shows HTTP error 500

Undefined Array Key error when uploading image on php

image source not readable

How to pass security cloudflare server with php curl

How to get array values using foreach in laravel

WAMP Virtual Host not working

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

api response laravel doesn't show

How to submit the custom form data in database in WordPress without plugin using ajax?

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

SilverStripe unable to populate multiple member Childs

(Laravel) How to delete multiple models including optional relationships?

About Contact Privacy policy Terms and conditions