views:

157

answers:

3

I have this code:

//fetch data
$data = $_POST['list'];
echo($data);
echo('<br>then<br>');
$data = str_replace("\t", " ", $data);

echo($data);
$matches = array();
$user = array();      
preg_match( "/(.+?) ((?:[A-Z])(?:[0-9]+:){3}[0-9]+) ([0-9]+) \/([0-9]+) ([0-9]+) \/ ([0-9]+)/", $data, $matches ); 
list(,$user['base'],$user['location'],$user['econ'],$user['maxecon'],$user['ports'],$user['maxports']) = $matches;

$base = $users['base'];
$_SESSION['base'] = $base;

$location = $users['location'];
$_SESSION['location'] = $location;

//intergers
$econ =  intval(($users['econ']), 10);
$_SESSION['econ'] = $econ;

$maxecon =  intval(($users['maxecon']), 10);
$_SESSION['maxecon'] = $maxecon;

$ports =  intval(($users['ports']), 10);
$_SESSION['ports'] = $ports;

$maxports =  intval(($users['maxports']), 10);
$_SESSION['maxports'] = $maxports;

I know the preg_match pattern is correct as it is used successfully on another page for the same desired intention in a list where action was performed on each line. In this example $data contains the data but $base, $location and $tecon remain empty.

What have I missunderstood or done wroung?

Resources: see it in action here:http://www.teamdelta.byethost12.com/postroute.php
look at entire code here:http://www.teamdelta.byethost12.com/postroute.txt

A: 

Can you do something like a var_dump of the $data var before the preg_match, and a var_dump of the $matches array after the preg_match?

Anytime I had these kind of issues, there was always a mismatch between the data format and the regex. Something stupid, often.

sydarex
A: 

please turn error reporting to a higher level:

error_reporting(E_ALL | E_NOTICE);

And you’ll notive whats wrong

Maciej Łebkowski
A: 

Found answer.. List cannot be called for strings. As it is a single preg-match operation values can be called directly from the match array.

Arthur