A simple implementation of PHP inserting new characters at a specified position in a string
Because the project uses the DataTable table to load the background data, and the table queries the virtual machine's selected policy state, the idea is to first take out the contents of the Policy table and form a ' <select><option value= ' 1 ></option >[n a option]</select> ' string that, when traversing the list of virtual machines, spells his policy value into a string such as ' value= 1 ', and then uses explode () and implode () function, the new string is returned to the foreground, and the selected state is implemented.
$option = ' <select class= ' sla_list ' > ';
Remove all policies $sla _query = $this->db->select (' sla_id, Name ')->get (' SLA ');
$sla _res = $sla _query->result_array ();
if (!empty ($sla _res)) {$option. = ' <option value= ' 0 ' > unprotected </option> '; foreach ($sla _res as $k 1 => $v 1) {$option. = ' <option value= '. $v 1[' sla_id ']. ' > '. $v 1[' name '].
' </option> ';
$option. = ' </select> ';
else {$option. = ' <option value= ' 0 ' > unprotected </option></select> ';
//Select the default protection policy $VM _query = $this->db->select (' sla_id ')->where (' vm_id ', $VM _id)->get (' TASK_VM ', 1);
$VM _res = $VM _query->row_array ();
if (Is_null ($vm _res[' sla_id ')) $res [' sla_id '] = 0; $selected = ' value= '. $VM _res[' sla_id '].
'"';
$new _str_arr = Explode ($selected, $option);
$new _option = Implode ("{$selected} selected", $new _str_arr);
The above is a small series for everyone to bring PHP in the string specified position insert new characters simple implementation of the full content, I hope that we support cloud-Habitat Community ~