Value with various data like to find it in other pages in PHP

2

I have the following code pagina1.php

<input type="checkbox" class="case" name="case[]" value="<?php printf("%s",$row["nombre"]); printf("|"); printf("%s",$row["fecha"]); printf("|"); printf("%s",$row["hora"]);?>">

I send it to pagina2.php

$evento = $_POST["case"];

<form  id ="form3" action="pagina3.php" method="post" name="forma3">

    foreach ($evento as $value) {    
    printf("<input type=\"hidden\" name=\"evento[]\" value=\"%s\" align=\"right\"/>",$value);
    }
</form>

The result if I give an echo to $value It is as follows:

texto101.zip|2015-09-03|'04:00:00'

On page3.php I receive it like this

$evento = $_POST["evento"];

How is it possible to store each value from $evento in variables and something like this:

name=texto101.zip
fecha=2015-09-03
hora='04:00:00'
    
asked by Houdini 12.10.2016 в 19:36
source

3 answers

6

PHP's explode() function divides a string into several strings from a delimiter passed by parameter. So in page2.php you could do:

$evento = $_POST["evento"];
list( $name, $fecha, $hora ) = explode( "|", $evento );

Then you would have the content you're looking for in each of those variables.

    
answered by 12.10.2016 / 19:56
source
2

The response of @Lucas aims to take what you receive on page3.php, that is:

$evento = $_POST["evento"];
list( $name, $fecha, $hora ) = explode("|", $evento );

echo "name: $name <br>";
echo "fecha: $fecha <br>";
echo "hora: $hora";

What you are doing explode , is to separate your string by the |

delimiter

Subsequently the list , what it does is save every position it found in a variable, it would be the same as doing:

$arreglo = explode( "|", $evento );
$name = arreglo[0];
$fecha = arreglo[1];
$hora = arreglo[2];

Understand?

If you want to pass the variables already separated from page 2 to page 3, you should pass them as a hidden hidden with each value, assuming you did what is above and passed them to the view or page2.

<input type="hidden" name="name" value="<?php echo $name; ?>" />
<input type="hidden" name="fecha" value="<?php echo $fecha; ?>" />
<input type="hidden" name="hora" value="<?php echo $hora; ?>" />

Greetings

    
answered by 13.10.2016 в 00:22
1
$array = explode( "|", $evento );

here you separate the string with the delimiter |

$nombre = array[0];// obtnes los strings por sus indices
$fecha = array[1];
$hora = array[2];

If you need to save these data temporarily you can also use the variables

$_SESSION[info] = $array;
    
answered by 13.10.2016 в 00:32