A much clearer example of what i need
Posted: Mon Mar 08, 2010 1:04 am
Ok this will demonstrate what where I think the problem is
Code: Select all
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.php');
$data = new Database();
$data->connect();
session_start();
if(isset($_POST['fname']))
{
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['phone']))
{
$_SESSION['formArray'][] = array("fname" => $_POST['fname'],
"lname" => $_POST['lname'],
"phone" => $_POST['phone']);
}
else
{
print "Error: Not enough form data";
}
}
$mystring = $_SESSION['formArray'];
$test = json_encode($_SESSION['formArray']);
$str1 = "'"."(". $test .")"."'".";";
//echo $test ."<br/>";
echo $str1 ."<br/>";
echo "here it is"."<br/>";
$str = $str1;//'([{"fname":"755","lname":"755","phone":"755"}])'; this works when i copy and past the output in but not when i pass it from str1
$str = substr($str, 1, strlen($str) - 2); // remove outer ( and )
$str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $str); // fix variable names
$output = json_decode($str, true);
var_dump($output);
?>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bretts Array</title>
</head>
<body>
<form name="info" action="" method="post">
first name: <input type="text" name="fname" value=""><br/>
last name:<input type="text" name="lname" /><br />
phone number:<input type="text" name="phone" /><br />
<input type="submit"/>
</form>
</body>
</html>
I want to give $str whats in str1 Im confused why im still getting null