0

I have a list of status and subtsatuses that I need to "translate"/convert to a new one, just like in the example below:

Old Status        Old Substatus     New Status          New Substatus
-----------------------------------------------------------------------
4-Defer          Code Freeze           11          Code/Hardware Bug (Response/Resolution), Dev Priority = 4, Confirmed = ‘Y’
4-Defer          Future Project        11          Code/Hardware Bug (Response/Resolution), Dev Priority = 4, Confirmed = ‘Y’
4-Defer          No Plan to Fix        11          Code/Hardware Bug (Response/Resolution), Dev Priority = 4, Confirmed = ‘Y’
4-Defer      No Resource Available     11          Code/Hardware Bug (Response/Resolution), Dev Priority = 4, Confirmed = ‘Y’
...
11-Closed           Duplicate          96          Closed, Duplicate Bug
11-Closed        Not Reproducible      91          Closed, Could Not Reproduce
11-Closed         Not a Defect         92          Closed, Not a Bug

Is there a way I can declare an array in pairs (via multidimension array), or combined with classes, in order to make this conversion?

something like    (11, "Duplicate") => (96, "Closed, Duplicate Bug")

Any help will be greatly appreciated.

Thanks in advance!

Cristina
  • 77
  • 8
  • You would need to concatenate them as an array key `$arr['11-Duplicate'] = array(96, 'closed, duplicate bug')` but note that if you have multiples like `11-Duplicate` they will overwrite one another. The keys must be unique. – Michael Berkowski Mar 10 '14 at 15:18
  • Can you post a larger sample of what you would expect an output array to look like? Pseudocode is okay for the keys... – Michael Berkowski Mar 10 '14 at 15:19

1 Answers1

0

Assuming you have this as a text file and can read each line in turn I would probably do the following. I noticed that your values are separated by 2 or more spaces. This is a good way of identifying the delimeter.

So this example is working on just one of those lines but assume you are looping through each line and doing this.

// Here's just one line, pushed into $str
$str    = "4-Defer          Code Freeze   11    Code/Hardware Bug etc";

// Use the multiple spaces as a delimeter and replace them with #^# (a single delimeter)
$str    = preg_replace("/[ ]{2,99}/i","#^#",$str);

// Explode on the delimeter
$str    = explode("#^#",$str);

// Now you have an array containing each column data
// You can build your new array by directly referring to the columns
print "<pre>";
print_r($str);
print "</pre>";

Hope that helps, or sparks some ideas!! PS - I realise that the large spaces could be single tabs (\t) but I'm going to guess they are just spaces for the sakes of the example :)

Adam
  • 359
  • 3
  • 5
  • Hi Adam. Actually, I have it as table in a Word document which explains how to make the conversion from the old to the new format (for several fields, not just this one), so no spaces nor tabs there (I just put that there as an example). I'll need to make this conversion for thousands of files, so that's why I was wondering if there's a short and effective way to do it? – Cristina Mar 10 '14 at 15:48
  • So you have a load of data in word documents? - I guess you'd need some kid of handler to extract plain text from a word document, then store the output and THEN read the plain text versions? Here's an example of extracting text from docs. Not done it myself in any detail but hope that's a start. http://stackoverflow.com/questions/5540886/extract-text-from-doc-and-docx – Adam Mar 11 '14 at 09:38