English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have the following block of PHP code:

if(!empty($Array[$i]['test_drive'])) {
$tmpStr .= "".$Array[$i]['september']."
";
}

$outputStr .= $tmpStr;


"september" is the name of a data field. The data being outputted by "september" will be calendar dates, space separated:

16-sept 20-sept 28-sept

So what PHP code would I use to have that data render on my page like this:

September 16
September 20
September 28

?

2006-08-29 00:48:01 · 3 answers · asked by achtungbaby 3 in Computers & Internet Programming & Design

3 answers

If the data in your "september" array is just string data, you have to put in extra lines of code split up the date and month information (using explode() ), use if-else condition to convert "sept" to "September". Then, arrange to print out the format that you want.

On the other hand, if the data in the array is Unix timestamp (http://en.wikipedia.org/wiki/Unix_timestamp), you can use date() function, i.e:

print date('F j',$Array[$i]['september'])
would produce:
September 16 (for $Array[$i]['september'] = 1158364800)

to get the format you want.

As for the printing a date on everyline, a simple loop with line break + catridge return at the end of every output will do it.

Good luck.

2006-08-29 01:13:32 · answer #1 · answered by jakjak 2 · 0 0

You could use the split() function:

function split_date($outputStr) {
$outputStr_array = split("-",$outputStr );
$date_month = $outputStr_array[1];
$date_day = $outputStr_array[0];

if ($date_month == 'sept') {
$date_month = "September";
}
elseif ($date_month == 'dec') {
$date_month = "December";
}
echo $date_month . " " . $date_day;
echo "
";
}

$outputStr= "28-sept";
split_date($outputStr);

$outputStr= "15-dec";
split_date($outputStr);

2006-08-29 13:46:31 · answer #2 · answered by Michael T 2 · 0 0

whats an if for?

http://www.rci.rutgers.edu/~jfulton/php1/loops.html

2006-08-29 07:54:38 · answer #3 · answered by ★Greed★ 7 · 0 0

fedest.com, questions and answers