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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:21:15+00:00 2026-06-16T23:21:15+00:00

I have an array of data containing some domains with TLD extensions. I want

  • 0

I have an array of data containing some domains with TLD extensions. I want to collect the domain name and TLD extension seperately.

E.g. From “hello.com” I want to collect “hello” as one variable, and then collect “.com” as another variable.

Another E.g. IMPORTANT, from “hello.co.uk” I want to collect “hello” as one variable, and then collect “.co.uk” as another variable.

My current code using pathinfo() will work correctly on “hello.com”, but not “hello.co.uk”. For “hello.co.uk” it will collect “hello.co” as one variable, and then collect “.uk” as another variable.

Here is the code I am using:

// Get a file into an array
$lines = file($_FILES['file']['tmp_name']);

// Loop through array
foreach ($lines as $line_num => $line) {
    echo $line;

    //Find TLD
    $tld = ".".pathinfo($line, PATHINFO_EXTENSION);
    echo $tld;

    //Find Domain
    $domain = pathinfo($line, PATHINFO_FILENAME);
    echo $domain;
    }

Hopefully I explained that well enough.
I use stackoverflow a lot but couldn’t find a specific example of this.

Thanks

  • 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-16T23:21:16+00:00Added an answer on June 16, 2026 at 11:21 pm

    Instead of using functions intended for files, you could just use some simple string manipulation:

    $domain = substr($line, 0, strpos($line, "."));
    $tld = substr($line, strpos($line, "."), (strlen($line) - strlen($domain)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some array data returned from an ajax call consisting of an image
I have got the array containing some data, say, a header and a real
I have a 1d array containing Nd data, I would like to effectively traverse
I have a problem related to an array data which fetched from an external
I have a documentFragment with several child nodes containing some .data() added like so:
I have a UITableViewController containing some very basic data. Assume each row just contains
I have this query in Ruby to fetch some data from the database: @mastertest
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
I have a 2-d array, containing only 0 or 1. I want to sort
I have an array that has an array containing more data stored into one

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.