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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:11:26+00:00 2026-05-16T06:11:26+00:00

I need to be able to parse this sort of data in PHP: Acct:

  • 0

I need to be able to parse this sort of data in PHP:

 Acct: 1 
 email       : bleh@gmail.com 
 status      : online 
 -------------------------------------------------- 

 Acct: 2 
 email       : dfgg@fgfg.com     
 status      : banned 
 -------------------------------------------------- 

 Acct: 3 
 signedupname  : SomeUsername     
 somethingelse  : offline 
 -------------------------------------------------- 

As you can see the data is largely random. The only thing that remains the same is the ----- seperating each entry and the Acct: 1 bits. The padding between each : often changes as does the variable to represent each bit of data.

I’ve tried going through and parsing it all myself using regex but I am defenately not skilled enough to be able to do it properly. At the end of this I want data according to the following:

Acct: <integer>
var1: <string>
var2: <string>

If that makes any sense at all. It doesn’t need to be that effeciant, as I will need to do this about once a day and I do not mind waiting for how-ever long it needs.

Thank you. 🙂

Edit: This is what I did on my own:

<?php

$data = file_get_contents('records.txt');
$data = explode('******** Saved Host list with acct/variables ********', $data);
$data = explode('--------------------------------------------------', $data[1]);

foreach($data as &$dataz)
{
    $dataz = trim($dataz);
}

$data = str_replace('Acct:', "\nAcct:", $data);

foreach($data as $dataz)
{
    preg_match('/Acct: (.*)/', $dataz, $match);
    $acct = $match[1];
    preg_match('/: (.*)/', $dataz, $match);
    $var1 = $match[1];
    echo $var1;
}

?>

I got as far as extracting the Acct: part, but anything beyond that I simply can’t get my head around.

  • 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-16T06:11:26+00:00Added an answer on May 16, 2026 at 6:11 am

    This piece of code will take your entire input and produce an associative array for each record in your input:

    // replace ----- with actual number of dashes
    foreach (explode('-----', $input) as $entry) {
      $entry = trim($entry);
      $record = array();
      foreach (explode("\n", $entry) as $line) {
        $parts = explode(':', $line);
        $varname = trim($parts[0]);
        $value = trim($parts[1]);
        $record[$varname] = $value;
      }
      // Do anything you want with $record here
    }
    

    Edit: I just had a look at the code you posted. You really don’t need regular expressions for what you’re trying to do. Regex can be really handy when used in the right place, but most of the time, it’s not the right thing to use.

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

Sidebar

Related Questions

I have binary ASN.1 data objects I need to parse into my Java project.
I need to be able to parse both CSV and TSV files. I can't
I need to parse this xml. I am trying dom parser. I am not
I guess this is sort of two questions that are tied together. Related questions
I have some JSON data that looks like this: { 910719: { id: 910719,
I have been trying for days to figure out how to parse this JSON
I am working on a safari extension in which I need to parse a
For the sake of being able to search and index/sort an array I have
I need help with my program. So I have com port connection ( gps
I'm relatively new to Java programming and need to parse a complex JSON object

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.