我有从另一个服务作为字符串发布的数据:
heading="firstname","lastname"&user_1382926="Mike",Smith"&user_1383059="Sonny","Williams"&user_1303EM000014="Mike","Jones"
我在解析这个时迷失了方向,因为 user_* 可以是任何东西,它不是一致的。
我试过了:
$query = explode('&', 'heading="firstname","lastname"&user_1382926="Mike",Smith"&user_1383059="Sonny","Williams"&user_1303EM000014="Mike","Jones"');
$params = array();
foreach( $query as $param ){
list($name, $value) = explode('=', $param);
echo $params[urldecode($name)][] = urldecode($value);
}
但它只是给了我:
"firstname","lastname""Mike",Smith""Sonny","Williams""Mike","Jones"
我希望能够将其发布到:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$stmt = $mysqli->prepare("INSERT INTO usertest (firstname,lastname) VALUES (?,?)");
$stmt->bind_param('ss', $firstname, $lastname);
$stmt->execute();
我如何解析这个以便正确发布?