Page 1 of 1

Extracting data in variable

Posted: Sat Sep 20, 2008 3:17 am
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

Re: Extracting data in variable

Posted: Sat Sep 20, 2008 3:40 am
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".

Re: Extracting data in variable

Posted: Sat Sep 20, 2008 3:40 am
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']);
?>
 

Re: Extracting data in variable

Posted: Sat Sep 20, 2008 4:55 am
by 3hhh
Thank you guys! I really appreciated it! :)