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

  • SEARCH
  • Home
  • 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 6973691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:26+00:00 2026-05-27T17:08:26+00:00

Or maybe I’m doing something else wrong. <?php $date = 2011-12-31|12-31; $fileData = file(‘something.txt’);

  • 0

Or maybe I’m doing something else wrong.

<?php
$date = "2011-12-31|12-31";

$fileData = file('something.txt'); // Get file contents as array
print_r($fileData);
echo "<br /><br />";

array_unshift($fileData, $date); // Add date to [0]
print_r($fileData);
echo "<br /><br />";

$cleanData = array_unique($fileData); // remove dupes
print_r($cleanData);
echo "<br /><br />";
?>

Prints out as:

Array ( [0] => 2011-12-31|12-31 [1] => 2011-12-30|12-30 [2] => 2011-12-29|12-29 ) 

Array ( [0] => 2011-12-31|12-31 [1] => 2011-12-31|12-31 [2] => 2011-12-30|12-30 [3] => 2011-12-29|12-29 ) 

Array ( [0] => 2011-12-31|12-31 [1] => 2011-12-31|12-31 [2] => 2011-12-30|12-30 [3] => 2011-12-29|12-29 ) 

Here is something.txt:

2011-12-31|12-31
2011-12-30|12-30
2011-12-29|12-29

I suspect that there might be eol or lf markers in the $fileData. If this is the case, is there an easy way to remove them?

  • 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-05-27T17:08:26+00:00Added an answer on May 27, 2026 at 5:08 pm

    The strings in the array returned by file() have new line characters at the end, making them not equal to strings which do not. You can tell file() to not include these characters by adding FILE_IGNORE_NEW_LINES as the 2nd parameter:

    file('something.txt', FILE_IGNORE_NEW_LINES);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe I'm going about this wrong, but I'm hoping I can get some insight.
Maybe someone could explain the difference between property: in .h file @property(nonatomic,retain) NSString *someString;
maybe you could help me understand why I get an unhandled exception Invalid XAML
Maybe this is gonna sound naive and all, but is there something even remotely
Maybe I'm missing something but why does visual studio break execution to tell me
Maybe something really simple, I got really big problem with... ORM result. I'm loading
Maybe it's too late in Germany (1:04AM) or maybe I'm missing something... How can
Maybe I'm searching with the wrong keywords, but I can't find a solution to
Maybe I'm missing something simple but I can't figure out after some time looking
Maybe there is something screwy with Coldfusion's Ajax functions, but I cant figure this

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.