Hey.
I'm having trouble with the length of one field in this array i read/write to a csv-file for my system here at work.

This is my code:

$linecontent[49]     = $article;
$newarticle		= str_pad("".$linecontent[49]."", 10);	
$linecontent[49]     = "\"".$newarticle."\"";

The trouble is that the length of the field [49] differs from line to line allthough I've used str_pad. Isn't that the whole idea about str_pad, or is my code wrong?

Help would be much appreciated.

    Hi!
    It`s possible I miss your point, but if the thing is to make all lines same length this is a way to do it.

    $longestLine = 0;
    
    foreach($linecontent as $line) {
    	$lineLength = strlen($line);
    	if($lineLength > $longestLine)
    		$longestLine = $lineLength;
    	}
    
    $newArticle      = str_pad($article, $longestLine - strlen($article));
    $linecontent[49] = "\"$newArticle\"";
    
      Write a Reply...