Jump to content

PHP changing a format inside an array


s_ainley87

Recommended Posts

<?php
class CreateCSV{
function create($sql, $isPrintFieldName = true, $isQuoted = true){

	$q = mysql_query($sql) or die("Error: ".mysql_error());

	$csv = $head = $ctn = '';
	$hasPrintHead = false;

	while($r = mysql_fetch_assoc($q)){

		if(!$hasPrintHead && $isPrintFieldName == true){
			$csv_value = array();
			foreach($r as $field => $value){
				$csv_value[] = $field;
			}
			$hasPrintHead = true;
			$csv .= implode(',', $csv_value)."<br/><br/>";
		}

		//Print the content...
		$csv_value = array();

		foreach($r as $field => $value){
			$cvs_value = date("d.m.o", $cvs_value[1]);
			$csv_value[] = $isQuoted == true ? '"'.$value.'"' : $value;

		}

		$csv .= implode(',', $csv_value)."<br/><br/>";

	}
	return $csv;
}
}
?>

 

The above code create a layout that can be copied across to excell and saved as csv.  My problem is that I cannot for the life of me work out how to change the timestamp data I have within the array to m.d.y format. The array is called $csv_value and I know the timestamp is held in [2].

 

Does any one have any ideas?

Link to comment
https://forums.phpfreaks.com/topic/114848-php-changing-a-format-inside-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.