A simple implementation _php instance of PHP inserting new characters at a specified position in a string

Source: Internet
Author: User
Tags explode

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.