Php inserts new characters at the specified position of the string, and php Strings specify characters

Source: Internet
Author: User

Php inserts new characters at the specified position of the string, and php Strings specify characters

Because the project uses a DataTable table to load background data and needs to connect the table to query the selected policy status of the VM, it is expected to retrieve the policy table content first, to form a '<select> <option value = "1"> </option> [n options] </select>' string, when traversing the Virtual Machine list, the policy value is combined into a string like 'value = "1" 'and then reused.Explode ()AndImplode ()Function to form a new string and return it to the foreground.

1 $ option = '<select class = "sla_list">'; 2 3 // retrieve all policies 4 $ sla_query = $ this-> db-> select ('sla _ id, name ')-> get ('sla'); 5 $ sla_res = $ sla_query-> result_array (); 6 if (! Empty ($ sla_res) {7 $ option. = '<option value = "0"> unprotected </option>'; 8 foreach ($ sla_res as $ k1 => $ v1) {9 $ option. = '<option value = "'. $ v1 ['sla _ id']. '"> '. $ v1 ['name']. '</option>'; 10} 11 $ option. = '</select>'; 12 13} else {14 $ option. = '<option value = "0"> unprotected </option> </select> '; 15} 16 17 18 // select the default protection policy 19 $ vm_query = $ this-> db-> select ('sla _ id ') -> where ('vm _ id', $ vm_id)-> get ('Task _ vm ', 1); 20 $ vm_res = $ vm_query-> row_array (); 21 if (is_null ($ vm_res ['sla _ id']) $ res ['sla _ id'] = 0; 22 $ selected = 'value = "'. $ vm_res ['sla _ id']. '"'; 23 $ new_str_arr = explode ($ selected, $ option); 24 $ new_option = implode (" {$ selected} selected ", $ new_str_arr );

 

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.