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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:55:43+00:00 2026-06-03T05:55:43+00:00

I have a text document that is opened and read by php that looks

  • 0

I have a text document that is opened and read by php that looks like this

ABC: 123

DEF: 456

GHI: 789

So basically it is one piece of text ended with a colon, followed by another piece of text. To separate the lines there is a line break (i.e. ” \n “)

Is it possible to have this go into an array separated by the colon and the line break? So that when I print the value it should look like this:

” ABC:123,DEF:456,GHI:789 “

  • 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-03T05:55:45+00:00Added an answer on June 3, 2026 at 5:55 am

    First thing you need to do is split those lines up.

    $lines = explode("\n", $doctext);
    

    Next, process those lines one-by-one, splitting out the appropriate values.

    $output = array();
    foreach ($lines as $line) {
        $line_parts = explode(': ', $line, 2); // Limit 2, in case data contains a colon
        $output[$line_parts[0]] = $line_parts[1];
    }
    

    Then, you can find your array in $output. Note that you should also add some validation to these lines and what not, to make sure they contain the data you expect. Also, if the lines optionally contain a space between the colon and the value, or a variable amount of whitespace, then split on the colon and use trim() on the value, as appropriate.

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

Sidebar

Related Questions

I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
I have a text document that contains a list of numbers and I want
I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML =
I'm doing a bind to document like below, $(document).bind('click',doThis); But i have a text
I have an HTML document where I would like to semantically group text to
I have a v. large text document (no file extension) that has information about
My problem looks like this. I have a grid with documents (Id's). Now when
I have a text document that was poorly formatted for my purposes, and I
I have a php page and the behavior is this: the page is opened
I have a big load of documents, text-files, that I want to search for

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.