Extracting data in variable

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
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

Extracting data in variable

Post by 3hhh »

<select name="date">
<option value="20091101000000 20091131000000">Nov 09</option>
</select>

$_POST['date']

Considering if I want to extract the value "20091101000000" and "20091131000000" separately and store into TWO different variables, how do I do it?

Thank you in advance. I'm new to PHP. Hope to learn more from you guys
adroit
Forum Commoner
Posts: 37
Joined: Fri Aug 08, 2008 1:25 am
Location: India
Contact:

Re: Extracting data in variable

Post by adroit »

Hi Friend,

Use some character between 2 numbers ex. (20091101000000-20091131000000). Now explode this number by that character, you will get 2 array elements as "20091101000000" and "20091131000000".
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Extracting data in variable

Post by Ziq »

It's very easy. You should use the explode() function.

Code: Select all

 
<?
$array = explode(' ', $_POST['data']);
$first = $array[0];
$second = $array[1];
?>
 
But more useful variant it use both function: list() and explode():

Code: Select all

 
<?
list($first, $second) = explode(' ', $_POST['data']);
?>
 
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

Re: Extracting data in variable

Post by 3hhh »

Thank you guys! I really appreciated it! :)
Post Reply