$string_process = " '明治'=> array( 'dbms'=>'mysql', 'username'=>'sa', 'password'=>'sa', 'hostpost'=>'3306', 'database'=>'meiji', 'projectname'=>'meiji', ),
'kona'=> array( 'dbms'=>'mysql', 'username'=>'sa', 'password'=>'sa', 'hostpost'=>'3306', 'database'=>'22', 'projectname'=>'kona', ),\n\n";
$new = array();
preg_match_all ("/(\'.+\)),/", $string_process, $matches);
// print_r($matches[1]);
//处理结果
// Array
// (
// [0] => '明治'=> array( 'dbms'=>'mysql', 'username'=>'sa', 'password'=>'sa', 'hostpost'=>'3306', 'database'=>'meiji', 'projectname'=>'meiji', )
// [1] => 'kona'=> array( 'dbms'=>'mysql', 'username'=>'sa', 'password'=>'sa', 'hostpost'=>'3306', 'database'=>'22', 'projectname'=>'kona', )
// )
$string_process = preg_replace(array("/, *\\n/","/\', *\)/"),array("","')"),$string_process);
eval("\$arr = array(".$string_process.");");
//print_r($arr);
$str = "";
foreach($arr as $k=>$v){
$str.=$k.":";
foreach($v as $d){
$str.=$d.",";
}
}
trim($str,",");
echo $str;
是这个意思么
foreach ($string_process as $value) {
echo $value;//这里你可以对$value执行任何操作
}
上面的表达式实质是依次取出$string_process中的值,并赋给$value