• 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

Call to a member function fetch_field() on a non-object MySQLiDB

Unable to create lockable file - Laravel 8 & PHP 8

XSS attack still works despite htmlspecialchars() doing its work

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

How to load Codeigniter 4 lang file into an array variable

Laravel UUID generation

How to send parameters in soap request in php in __soapcall() function

Is it possible to change the table name in the migration file-laravel

Error Class "LaravelFortifyFeatures" not found

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

I can't delete my image when it is liked because of the foreign key in mysql

Laravel get user data with profile

How can I get user id from session in javascript?

Php - Sum up the numbers in an array one by one

About Contact Privacy policy Terms and conditions