我的 php 脚本中有这段代码
$concatenation= array('idcarde',$idcarde ,'mobile' ,$mobile ,'firstname',$firstname ,'lastname',$lastname ,'jour',$jour ,'mois',$mois ,'annee',$annee ,'adress',$adresse ,'Governora',$Governora);
$P = serialize( $concatenation );
$mabase = mysql_connect("localhost", "root", "root");
if ($mabase) {
mysql_select_db("mb", $mabase);
}
// insere toutes les donness provenant de $_POST
$sql = " INSERT INTO `test` SET
`formid` = '" . $formid . "',
`data` = '" . mysql_escape_string($P) . "',
`creation_date` = '" . date("Y-m-d H:i:s"). "' ";
@mysql_query($sql, $mabase);
此代码将数据保存在我的表测试中
在列数据中我有这个结果:
a:18:{i:0;s:7:"idcarde";i:1;s:8:"00688009";i:2;s:6:"mobile";i:3;s:8:"52199200";i:4;s:9:"firstname";i:5;s:6:"dumas";i:6;s:8:"lastname";i:7;s:6:"alen";i:8;s:4:"jour";i:9;s:2:"05";i:10;s:4:"mois";i:11;s:2:"05";i:12;s:5:"annee";i:13;s:4:"1951";i:14;s:6:"adress";i:15;s:54:"11 rue paris";i:16;s:9:"Governora";i:17;s:5:"france";}
我想知道我们怎样才能消除这个值 i:0 i:1 i:2 i:3 ...
我也尝试使用此代码:
它以这种格式保存数据:
["idtype","CIN","mobile","20390112","idcard","00731429","firstname","samia","lastname","Mejri","email","","gender","M.","deliv_lieu","","deliv_d","","deliv_m","","deliv_y","","birthdate_d","08","birthdate_m","10","birthdate_y","1944","address","36 rue Grece ","city","France","gouv","France","profession","","field","","bank","","agency","","friends","","followers","","blog_url","","website","","civil_status","","nickname","","zipcode",""]
但是使用前面的代码它显示如下
a:18:{i:0;s:7:"idcarde";i:1;s:8:"00688009";i:2;s:6:"mobile";i:3;s:8:"52199200";i:4;s:9:"firstname";i:5;s:6:"dumas";i:6;s:8:"lastname";i:7;s:6:"alen";i:8;s:4:"jour";i:9;s:2:"05";i:10;s:4:"mois";i:11;s:2:"05";i:12;s:5:"annee";i:13;s:4:"1951";i:14;s:6:"adress";i:15;s:54:"11 rue paris";i:16;s:9:"Governora";i:17;s:5:"france";}
这就是我想要的,但我想消除 i:0 i:1 i:2 i:3 直到 i:17
我现在尝试使用此代码:
$concatenation= array('idcarde',$idcarde ,'mobile' ,$mobile ,'firstname',$firstname ,'lastname',$lastname ,'jour',$jour ,'mois',$mois ,'annee',$annee ,'adress',$adresse ,'Governora',$Governora);
$P = serialize( $concatenation );
$M=preg_replace('~i:[0-9];~', '', $P);
$mabase = mysql_connect("localhost", "root", "root");
if ($mabase) {
mysql_select_db("mb", $mabase);
}
// insere toutes les donness provenant de $_POST
$sql = " INSERT INTO `test` SET
`formid` = '" . $formid . "',
`data` = '" . mysql_escape_string($M) . "',
`creation_date` = '" . date("Y-m-d H:i:s"). "' ";
@mysql_query($sql, $mabase);
此代码从数据 i:1 中消除;我:2;直到我:9;但不能消除
例如我:10;我:11;我:12;
我尝试解决这个问题但没有成功
$M=preg_replace('~i:~;~', '', $P);
我尝试将a :18更改为a:28
$P = serialize($concatenation) ;
//$M=preg_replace('~i:[0-9];~', '', $P);
$M=preg_replace('~i:[0-9]+;~', '', $P);
$M1=preg_replace('a:[0-9]+~', 'a:28', $M);
但它显示错误
我找到解决方案使用 $M1=preg_replace('~a:[0-9]+~', 'a:28', $M);
但我想说 28 是 $P 中的元素数
所以我应该在 $P 中找到元素的数量,然后在 a