Page 1 of 1

How to take a string and make it fields?

Posted: Tue Mar 22, 2011 4:23 pm
by schpanky
So, I have a script that I need to take a date (currently as a string), and split it up to enter them in forms... example:

Date: May 20, 2009

I need it to show up as:

<INPUT TYPE="TEXT" VALUE="MAY"> <INPUT TYPE="TEXT" VALUE="20"> <INPUT TYPE="TEXT" VALUE="2009">

I've looked up preg_match, which is what I was recommended, but I have no idea what the sample code is supposed to look like?

halp!

Re: How to take a string and make it fields?

Posted: Tue Mar 22, 2011 4:55 pm
by AbraCadaver
Assuming the text "Date: " is in there. If not then forgo the str_replace():

Code: Select all

$date = strtotime(str_replace('Date: ', '', 'Date: May 20, 2009'));
$month = date('F', $date);
$day = date('j', $date);
$year = date('Y', $date);

Re: How to take a string and make it fields?

Posted: Tue Mar 22, 2011 4:59 pm
by schpanky
AbraCadaver wrote:Assuming the text "Date: " is in there. If not then forgo the str_replace():

Code: Select all

$date = strtotime(str_replace('Date: ', '', 'Date: May 20, 2009'));
$month = date('F', $date);
$day = date('j', $date);
$year = date('Y', $date);

this worked PERFECTLY, THANK YOU!
Now, how do I buy you an e-beer? :drunk: