tags:

views:

182

answers:

3
<?php  
function aum($x) {
$contents = $_FILES['userfile']['tmp_name'];
$contents = file("$contents");
$aum = $contents[$x][13].$contents[$x][14].$contents[$x][15].$contents[$x][16].$contents[$x][17].$contents[$x][18].$contents[$x][19].$contents[$x][20].$contents[$x][21].$contents[$x][22].$contents[$x][23];
$faum = money_format('%(#1n',$aum)."\n";    
return $faum;
}
?>

Notice: A non well formed numeric value encountered in ./includes.php on line 28


Hi,

I'm getting the error above. Line 28 is: $faum = money_format('%(#1n',$aum)."\n";
I have three questions:

  1. Why am I getting this error notice and what should I do to fix it?
  2. Is there a better way to upload a CSV text file that has non-uniform comma separation into a HTML table? By "non-uniform" comma separation I mean: KEY DATA,DATA,,,$aum DATA,,,,,,DATA,,etc. As you can see, I am deriving $aum by using the file() function. I then count the number of characters from the right of the beginning of each row to get the fixed character number that corresponds with the $aum DATA. The $x variable corresponds to the row numbers in the file. Then I can return each $aum per row $x. I am new to PHP and would like to know if there is a smarter way to do this.

I appreciate any tips/advice that you might share.

thx,

+1  A: 

You need to have a look at $aum as it probably can't be formatted as a number.

Pop

echo $aum;
echo floatval($aum);

Before the error to see what you get. You might need to change the position you're looking at if you're picking up leading or trailing data.

Sohnee
Thanks, that answers my first question.
AME
+1  A: 

for the second question, fgetcsv is your friend to get data out of CSV files

http://ee.php.net/fgetcsv

Anti Veeranna
+1  A: 

For CSV parsing, a hand on approach is to use explode. I try this snippet of code

$string = "a,,b";
$result = explode(",", $string);
echo "<pre>".print_r($result, true)."</pre>";

And the output I get back is:

Array
(
    [0] => a
    [1] => 
    [2] => b
)
Extrakun