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 8506513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:36:42+00:00 2026-06-11T02:36:42+00:00

I’ve got a really bizarre problem here. I’m using the code below to upload

  • 0

I’ve got a really bizarre problem here. I’m using the code below to upload a txt file to my server via php.

    <form enctype="multipart/form-data" action="index.php" method="POST">
        <input type="file" name="uploadfile">
        <button>Submit</button>
    </form>

After uploading the file (which works fine) I convert the contents into an array via the following code:

$fp = @fopen($file, 'r'); 

if ($fp) { 
    $domains = explode("\n", fread($fp, filesize($file))); 
}

Then I run a preg_match to filter down the array:

$list = preg_grep('/^[a-z]+\.com$/', $domains);

I confirmed that $domains is getting populated with the data in the txt file, however when I run print_r($list) it’s only returning “array( )”

When I upload the same exact text file with FTP and run print_r($list) it works fine.

I also noticed when I upload the same text file with my FTP client the filesize of “domains.txt” is smaller than when I upload it using my html form. Any idea what’s going on here?

  • 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-11T02:36:44+00:00Added an answer on June 11, 2026 at 2:36 am

    This may have to do with line endings being automatically changed between UNIX and Windows by your FTP client.

    To resolve this, just use trim to cleanse every line before using preg_grep. Something like:

    foreach ($domains as $key => $domain) {
        $domains[$key] = trim($domain);
    }
    
    // or better use array_walk and closures PHP 5.3+
    array_walk($domains, function(&$e) { $e = trim($e); });
    

    The problem would be because your regular expression has explicit start-of-line and end-of-line anchors.

    BTW you could load up the whole file into an array of lines in one statement by just using the file function.

    $domains = file($file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.