Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:16:18+00:00 2026-06-11T10:16:18+00:00

Ive the following Code , a function take a list of usernames and put

  • 0

Ive the following Code , a function take a list of usernames and put in them in array then execute function called function get_all_friends , Code works fine and no error , my question here how to adjust the code if ive bulk of usernames lets say like 10k ?

Like reading from file include all usernames name and put them in array using

$file_handle = fopen("users.txt")

please advise !

<?PHP
    $user1 = "usernamehere";
    $user2 = "usernamehere";
    $user3 = "usernamehere";
    $u[] = $user1;
    $u[] = $user2;
    $u[] = $user3;

    function get_all_friends($users) 
    {
        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, TOKEN_KEY, TOKEN_SECRET);
        $list = array();
        foreach($users as $user)
        {
            $result = $connection->get( 'friends/ids', array(
            "screen_name"=> $user)
            );

            foreach($result->ids as $friend) 
            {
                $list[] = $friend;
            }

        }
        return $list;
    }

    //call the function
    $result = get_all_friends($u);

    foreach($result as $res)
    {
        $query = "INSERT INTO friends (userid, name, grade, flag) VALUES ($res, 'name', 100, 0 ) ";
        mysql_query($query);    
    }

    //to print the databse result
    echo "row<br />";
    $res = mysql_query("SELECT * FROM friends");  
    while ($row = mysql_fetch_assoc($res)) 
    {
        print_r($row);
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:16:19+00:00Added an answer on June 11, 2026 at 10:16 am

    Something like the following should work (untested):

    $filename = "users.txt";
    $file_handle = fopen($filename, "r");
    $contents = fread($file_handle, filesize($filename));
    $usernames = preg_split("/ (,|\\n) /", $contents);
    fclose($file_handle);
    

    The usernames must be separated by a comma or a new line.

    Although, if you are positive that the usernames will only be separated by a new line OR a comma, this code will be faster:

    $filename = "users.txt";
    $file_handle = fopen($filename, "r");
    $contents = fread($file_handle, filesize($filename));
    // new line:
    $usernames = explode("\n", $contents);
    // or comma:
    $usernames = explode(",", $contents);
    fclose($handle);
    

    Please choose only one of the $usernames definitions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got the following code which I hacked together from website examples. It works
Please help take a look at the following code, its working when calling function
I've following code to track geolocation of the user if (navigator.geolocation){ navigator.geolocation.getCurrentPosition( function(loc) {
I've the following code: $.each(css, function(i, v) { css[i] = this.replace('{bind}', bindName, css[i]); });
All, I've got the following code: var site_url = 'http://localhost/website/'; jQuery(#cancel_song_choice).click(function(event){ cancel_url = site_url
I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling
I've got the following code which depending on a url parameter changes and then
I have a simple, but perplexing problem, with Math. The following code will take
Ive got this code: loadData : function(jsonArray) { var id = $(this).attr(id); for(var i
Consider the following code (you can just put this in the developer console in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.