• 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

XML to CSV with PHP converter [problem with images grabing]

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

Return multiple values from a function using mysqli_fetch_assoc [closed]

Form Validation and Submission to database

HTML and PHP in one file

How can I access an array/object?

Make Calculator - When Button clicked the No shows in Textbox.

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

Symfony Make:Migration : The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

GA4 custom event from server side, can someone tell me how i can do the following code in php?

Can't call javascript alert alertify library from PHP

Call to undefined function openssl_decrypt

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

oauth-private.key does not exist or is not readable

Shortcode or PHP inside a shortcode in Wordpress

About Contact Privacy policy Terms and conditions