Forum Moderators: coopster
However, now I need the month to be converted to a numerical value - but since the month is an unknown (and called by the script I'm writing), I can't quite make it convert to the proper number.
Right now, I have this:
list($meta_month, $meta_year) = split('[ ]', $meta_value);
$y = $meta_year;
$m = date("n",mktime(0,0,0,$meta_month));
But the output is *always* "12", no matter what I do. I've also tried this:
list($meta_month, $meta_year) = split('[ ]', $meta_value);
$y = $meta_year;
$monthname = strtotime('$meta_month');
$m = date("n", $monthname);
but the output is usually "-1" - which tells me that something isn't going right.
Would anyone know how to convert the month name to the correct value? (September = 9, July = 7, and so on...) I just can't figure out what I'm doing wrong here.
Thanks :)
I don't think I can convert that into a UNIX timestamp, since the value can be *any* date (in fact, it could be anything at all - but I'm looking for a date), in the past or future. My script simply looks for those values so they can be grouped together. I need it - at this time - to be input as "September 2007" (for example) so I can use this data for other things within the script and generated output.
So, it's all well and good to have it as a UNIX timestamp, but that's not the purpose of this script. I just need to know how to turn the end-user input of "September" into "9".
Anyone have any ideas for that?
If not, would it be easier to have them input "9/2007", and then convert the "9" to "September" later on?
Explode off your year, and then use a series of if/else if statements to establish your Month values...
if ($month="January") {
$m="1";
} else if ($month="February") {
$m="2";
etc....
I could probably work it out further if necessary, but your code looks like you'll figure out my direction quickly enough...
Russ
Remove the single quotes - singles don't evaluate the contents as a variable, so you're trying to convert the literal text dollar-sign meta_month. You don't need quotes at all in this case.
I don't think I can convert that into a UNIX timestamp, since the value can be *any* date
You'll probably run into problems in the future trying to evaluate free-form inputted text as something meaningful. In your example, if I put in Sepptember 2007 it's all blown. A more structured method would be better, but you should, at the least, check it at input time so you can tell the user to correct it if it isn't in the format you'll need later.
$month = "July";
$monthnumber = array_search($month,$monthnames);
If you want January to be 1, either add one to $monthnumber or put a bogus entry as the first one in the array: $monthnames=array('nothing','January'...
Having the the original data in the correct format would be the best method though so, as stated before, you can easily convert it to what you want.
Also... would be probably easier to do the array like:
$monthnames = array(1 => 'January','February','March','April'....);
Wouldn't have to add the 1 later.
Thank you :)
This is what worked:
list($meta_month, $meta_year) = split('[ ]', $meta_value);
$y = $meta_year;
$m = $meta_month;
$ylink = "newsletter/" . $y;
$monthnames = array(
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December');
for($i=1;$i<=12;$i++){
if(date("F", mktime(0, 0, 0, $i, 1, 0)) == $m){
$month_number = $i;
}
}
the $ylink and $m values are what's echoed in the URL I'm creating...awesome - thanks to you all :)