note 51852 deleted from function.str-replace by felipe
| From: | felipe@php.net | Date: | Sun, 06 Jan 2008 12:49:02 +0000 |
| Subject: | note 51852 deleted from function.str-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134880@lists.php.net to get a copy of this message | ||
Note Submitter: will at 4lx dot net
----
This function is an example of replacing month numbers with the actual textual value.
<?php
function createMonths($month_start,$month_end) {
$month = array("1", "2", "3", "4", "5",
"6",
"7", "8", "9", "10", "11", "12");
$month_replace =
array("January","February","March","April","May","June",
"July","August","September","October","November",
"December");
$x_end = $month_end + 1;
// Add one to the value of the end month
for ($x = $month_start; $x < $x_end; $x++) {
$new_months .= $x.",";
// Count from the begin month to the end month
}
$new_months = substr($new_months,0,-1);
// Cut the last comma off the end month
$newmonth = explode(",", $new_months);
// Place each int month into an array
$newsmonth = str_replace($month,$month_replace,$newmonth);
// Replace the int month with a textual string
var_dump ($newsmonth);
// Dump the data
}
createMonths(1,3);
/* Will print array(3)
{ [0]=> string(7) "January" [1]=> string(8) "February" [2]=> string(5)
"March" } */
?>