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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:29:57+00:00 2026-05-27T10:29:57+00:00

i have a text field where users can enter a string of 15 numbers

  • 0

i have a text field where users can enter a string of 15 numbers only per line 50 lines max

i also need to filter out any duplicate values. so far i have this code

if(empty($_POST['text_field'])){$message = 'Please input values for the text_field.';}else{
    $text_field = $_POST['text_field'] ;
    $lines_unfiltered = array_slice(explode("\n", $text_field), 0, 50);
    $lines = array_unique($lines_unfiltered);
    print_r($lines);
exit;

but when i run it it with these numbers

5645646546545
2564545454544
5645646546545

it gives me all three lines and doesnt filter out the duplicate like it should

Array([0]=> 5645646546545 [1]=> 2564545454544 [2]=> 5645646546545)

any ideas?

  • 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-27T10:29:58+00:00Added an answer on May 27, 2026 at 10:29 am

    So, as the comments have pointed out, you need to strip out the \ns on each string.

    This could be done with:

    trim($text_field);
    

    Then you should be left with a properly formatted string that can be added to an array.

    Or you could do the one-liner that the other Jon proposed:

    $lines = array_unique(array_map('trim', array_slice(explode("\n", $text_field), 0, 50)));
    

    I added the array_unique function around everything to ensure that the result is only unique values.

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

Sidebar

Related Questions

I have a text field where users enter a URL string, which cannot contain
I have a text field in which user can enter any character he/she wants.
I have a form where users can add input fields with jQuery. <input type="text"
I have a type ahead text field, and when the user hits Enter I
If I have a text field with SWT, how can I get the field
I have a textbox in which I wanted a user to enter only numbers.
I have a form field that accepts large text from users. It is basically
I have a text field (flash.display.textField) for editing, but the default font does not
I have a text field and am looking to have if be valid for
Hi I have a text field which I would like to bind to a

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.