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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:36:10+00:00 2026-06-04T08:36:10+00:00

I would like to have a function that would return the best a multidimension

  • 0

I would like to have a function that would return the best a multidimension array of Associative arrays. I separated the whole output in three sections to make it read better.

What is the best way to parse such text? Where the output would be like

$output = array
  (
  "18"=>array(
    "type"=>"backup",
    "name"=>"PLC",
    "Description"=>"offline db",
    "state"=>"Executing",
    "Start Time"=>"05/16/2012 10:55:45.240272"
  ),  
  "17"=>array(
    "type"=>"restore",
    "name"=>"TYNDALE",
    "Description"=>"db",
    "state"=>"Executing",
    "Start Time"=>"05/16/2012 10:49:53.340805"
  ),
  "15"=>array(
    "type"=>"restore",
    "name"=>"carinya",
    "Description"=>"automatic incremental db",
    "state"=>"Executing",
    "Start Time"=>"05/16/2012 10:48:21.423945"
  )
  );

Section One + Two + Three are returned from linux command db2 list utilities show detail. So it would be an array of lines in php.

Section One

ID                               = 18
Type                             = BACKUP
Database Name                    = PLC
Partition Number                 = 0
Description                      = offline db 
Start Time                       = 05/16/2012 10:55:45.240272
State                            = Executing
Invocation Type                  = User
Throttling:
   Priority                      = Unthrottled
Progress Monitoring:
   Estimated Percentage Complete = 0
      Total Work                 = 3320093100 bytes
      Completed Work             = 255380 bytes
      Start Time                 = 05/16/2012 10:55:45.240303

Section two

ID                               = 17
Type                             = RESTORE
Database Name                    = TYNDALE
Partition Number                 = 0
Description                      = db 
Start Time                       = 05/16/2012 10:49:53.340805
State                            = Executing
Invocation Type                  = User
Progress Monitoring:
      Completed Work             = 117444608 bytes
      Start Time                 = 05/16/2012 10:49:53.340819

Section Three

ID                               = 15
Type                             = RESTORE
Database Name                    = CARINYA
Partition Number                 = 0
Description                      = automatic incremental db 
Start Time                       = 05/16/2012 10:48:21.423945
State                            = Executing
Invocation Type                  = User
Progress Monitoring:
   Phase Number                  = 1
      Total Work                 = 16781312 bytes
      Completed Work             = 16781312 bytes
      Start Time                 = 05/16/2012 10:48:21.423954

   Phase Number [Current]        = 2
      Description                = 20120513023104
      Completed Work             = 272633856 bytes
      Start Time                 = 05/16/2012 10:48:23.502822

   Phase Number                  = 3
      Description                = 20120514021520
      Completed Work             = 0 bytes
      Start Time                 = Not Started
  • 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-04T08:36:11+00:00Added an answer on June 4, 2026 at 8:36 am

    So the code I use is

    function db2listutilities(){
        global $db2Path;
    
        $status = array();
        $ProgressMonitoring=false;
    
        $cmd = $db2Path . "db2 list utilities show detail" ;
        unset($output);
        exec($cmd, $output);
        foreach ($output as $line){
            if( strpos($line,'Progress Monitoring:') !== false ){
                $ProgressMonitoring=true;
            }
            $tmp_array=explode("=", $line);
            if (count($tmp_array)>1){
                switch (trim($tmp_array[0])) {
                    case 'ID':
                        $id=$tmp_array[1];
                        $ProgressMonitoring=false;
                    break;
                    case 'Type':
                        $status[$id]['Type']=$tmp_array[1];
                    break;
                    case 'Database Name':
                        $status[$id]['Database Name']=$tmp_array[1];
                    break;
                    case 'Description':
                        if (!$ProgressMonitoring) {$status[$id]['Description']=$tmp_array[1];}
                    break;
    
                    case 'Start Time':
                        if (!$ProgressMonitoring) {$status[$id]['Start Time']=$tmp_array[1];}
                    break;
                    case 'State':
                        $status[$id]['State']=$tmp_array[1];
                    break;
    
                }
            }
        }
        $return=array();
        foreach ($status as $st) {
            $return[] = $st['Database Name']." - ".strtolower($st['Type'])." - ".$st['State']." - ".date("H:i",strtotime($st['Start Time']))."<BR>";
        }
        return implode("",$return);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that I would like to return 0 if a certain
I would like to have a function that can wrap any other function call.
I have a function that I use on index.php page and I would like
I have a function that is side-effect free. I would like to run it
I have a dataframe and I would like to apply a function that takes
I'd like to write a function that would have some optional code to be
I'm not very good at PHP and would like to have a PHP function
I have a function i would like to run onChange. This works fine with
I would like a JavaScript function to have optional arguments which I set a
I would like to temporarily override the kill-new function. I have a way I

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.