如何在代码点火器中分解数据库值



set_time_limit(0);
$config['upload_path'] =  'datauploads/';
$config['allowed_types'] = '*'; // CSV|csv|xlsx|xls
$config['max_size']	= '0';
$config['max_width']  = '0';
$config['max_height']  = '0';
$config['overwrite']  = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('file_upload'))
{
	$error = array('error' => $this->upload->display_errors());
	print_r($error);
}
else
{
	$file_name = $this->upload->file_name;
	$datas = array('upload_data' => $this->upload->data());
	$handle = fopen(base_url()."datauploads/$file_name", "r"); 			
	$fp = $handle;
	$BufferString= @fgets($fp ,4096);
	$BufferString   = explode("n",$BufferString);
	$childDropdown = array();
	$childDropdownArr = $this->dform_model->edit_field($modId,$recId);
	$childDropdown = explode("|",$childDropdownArr['def_value']);
	
	while (($datas = fgetcsv($handle,1024*30, ",")) !== FALSE) 
	{		
		$displayName = $datas[0];
		$databaseValue = $datas[1]; 
		if(!in_array($databaseValue,$childDropdown[$displayName]))
		$childDropdown[$displayName][] = $databaseValue;					
	}
}

在这里,我编写了一些代码来使用表格def_value列中的现有值更新新的 excel 值,我def_value有这样的值(0,US,US,|0,Monali,|(,在这里我需要从文本中分解 0 和 |我已经像这样爆炸了值$childDropdown = 爆炸("|",$childDropdownArr['def_value'](;但它不适用于分解这两个值。如何使用代码点火器来做到这一点,任何人都可以帮助我..

function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return  $launch;
}
$text = "(0,US,US,|0,Monali,Monali,|)";
$exploded = multiexplode(array("0","|","|0"),$text);
print_r($exploded);

资料来源:https://www.php.net/manual/en/function.explode.php#111307

相关内容

  • 没有找到相关文章

最新更新