• 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

Jquery DataTables: Data not displaying in table via Ajax

php curl_exec() Connection refused when retrieving a remote image

nginx err_connection_refused, can anyone help me?

MySQL order by field in Eloquent

Getting public posts of a random user from Facebook API

Laravel Displaying image from database

PHP 8.1: strftime() is deprecated

How Can I Do LIMIT 1, 2 In WP_Query

How to redirect to another page after n seconds in wordpress without using javascript?

How to modify CSS in a specific page of the WP admin dashboard (backend)

how to retrieve the first and last instance of a row in pdo dataset

Laravel 5.1 Unknown database type enum requested

XDebug not working in VScode for php debugging

JQuery content editable div and text box on submit not sending POST

HTML and PHP in one file

About Contact Privacy policy Terms and conditions