【问题标题】:how to explode the database values in codeigniter如何在codeigniter中爆炸数据库值
【发布时间】:2020-05-25 05:53:03
【问题描述】:

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,Monali,|),这里我需要爆炸 0 和 |从文字。我已经爆炸了这样的值 $childDropdown = explode("|",$childDropdownArr['def_value']);但它不适用于爆炸这两个值。如何使用codeigniter做到这一点任何人都可以帮助我..

【问题讨论】:

  • 发布预期输出

标签: php html sql codeigniter


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多