lunes, 31 de enero de 2011

Passing variables with spaces within them in PHP

advice for passing string variable in PHP - cómo pasar una variable si tiene espacios en PHP?

For example, i want to pass a datetime variable using PHP to another PHP script.

The main problem was how to handle the spaces, such as the following: 2011-01-29 08:50:00 ???
well, my solution was to put together the variable using the explode function.

So the variable must be converted to 2011-01-29_08:50:00, doing this, we have only one string.

$fecha_entrada=explode(" ",$datein);
$fecha_salida=explode(" ",$dateout);


when the other script receives the variable, again with the explode() function we separate the string getting it back to its original value.

$datein2 = $_GET['datein']; //variable viene con guión, la vamos a quitar
$dateout2 = $_GET['dateout']; //variable viene con guión, la vamos a quitar

//procesando variables de fechas recibidas desde un error:
$entree=explode("_",$datein2); //separando variables del guión bajo

$datein=$entree[0]." ".$entree[1]; // regresando las variables a su estado natural. ay ay ay!
$dateout=$sortie[0]." ".$sortie[1];