note 51851 added to function.preg-replace
| From: | will at 4lx dot net | Date: | Wed, 13 Apr 2005 01:04:02 +0000 |
| Subject: | note 51851 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87921@lists.php.net to get a copy of this message | ||
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" } */
?>
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51851
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51851&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51851&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51851&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51851&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51851&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51851&report=yes
Search -- http://master.php.net/manage/user-notes.php