How to take a string and make it fields?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
schpanky
Forum Newbie
Posts: 3
Joined: Mon Mar 07, 2011 12:32 pm

How to take a string and make it fields?

Post 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!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
schpanky
Forum Newbie
Posts: 3
Joined: Mon Mar 07, 2011 12:32 pm

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

Post 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:
Post Reply