----- Original Message -----
From: "Wade Smart"
02052008 1840 GMT-6
A piece of hardware puts out a formatted report daily that I need to
extract the data from. There are 13 columns of information. The data in
the columns are from 1 to 5 possibly 6 places with no 0's as place holders.
What I need to do is remove all the spaces except 1 between all the
columns.
I thought about doing something like:
do{ $pos_start = $pos_start + 1; }
while ( !chr(32);
But that doesnt work.
Would someone give me a suggestion.
Wade
---------------------------------
Hi Wade,
It would help if you gave a text example of the output you are
decoding.
You mentioned columns but I don't know if there separated by spaces, tabs or
in html?
I will have a guess and give some examples -
$text = '<td>5</td><td>1</td><td> </td><td>4</td>';
$tmp = str_replace('<td> </td>', '<td>0</td>', $text);
// now '<td>5</td><td>1</td><td>0</td><td>4</td>'
$tmp = str_replace('<td>', '', $tmp);
// now '5</td>1</td>0</td>4</td>'
$tmp = str_replace('</td>', ' ', $tmp);
// now '5 1 0 4 '
$tmp = trim($tmp);
// now '5 1 0 4'
$tmp = str_replace(' ', '|', $tmp);
// now '5|1|0|4'
// if you don't want zero's then -
$tmp = str_replace('0', ' ', $tmp);
// now '5|1| |4'
// convert to array
$data = explode('|', $tmp);
// array = ['5', '1', ' ', '4']
another example
$text = '1 2 3 7 9
2 5 1 5 6
9 4 9 0 6
0 6 7 9 2';
$tmp = str_replace(' ', ' # ', $text);
now -
1 2 3 # 7 9
2 5 1 # 5 6
9 # 4 9 0 6
0 6 7 # 9 2
$tmp = str_replace(' ', '|', $tmp);
now -
1|2|3|#|7|9
2|5|1|#|5|6
9|#|4|9|0|6
0|6|7|#|9|2
$tmp = str_replace('#', ' ', $tmp);
now -
1|2|3| |7|9
2|5|1| |5|6
9| |4|9|0|6
0|6|7| |9|2
standardise Mac/DOS/Unix/Windows formats to Unix - preserving white space
$tmp = str_replace("\r\n", "\r", $tmp);
$tmp = str_replace("\r", "\n", $tmp);
$tmp = explode("\n", $tmp);
now - ['1|2|3| |7|9', '2|5|1| |5|6', '9| |4|9|0|6', '0|6|7| |9|2']
foreach($tmp as $oneline)
{
$data[] = explode("|", $oneline);
}
now -
[['1', '2', '3', ' ', '7', '9'],
['2', '5', '1', ' ', '5', '6'],
['9', ' ', '4', '9', '0', '6'],
['0', '6', '7', ' ', '9', '2']]
OR
foreach($tmp as $oneline)
{
$tmparray = explode("|", $oneline);
unset($outputarray);
$outputarray['apples'] = $tmparray[0];
$outputarray['peaches'] = $tmparray[1];
$outputarray['pairs'] = $tmparray[2];
$outputarray['plums'] = $tmparray[3];
$outputarray['nectarines'] = $tmparray[4];
$outputarray['mellons'] = $tmparray[5];
$data[] = $outputarray;
}
now -
[[apples:'1', peaches:'2', pairs:'3', plums:' ', nectarines:'7',
mellons:'9'],
[apples:'2', peaches:'5', pairs:'1', plums:' ', nectarines:'5',
mellons:'6'],
[apples:'9', peaches:' ', pairs:'4', plums:'9', nectarines:'0',
mellons:'6'],
[apples:'0', peaches:'6', pairs:'7', plums:' ', nectarines:'9',
mellons:'2']]
Hope that helps, Rob.