How to parse .ini file and generate code in php -


i'm new .ini , php. i'm using pfbc generate form fields. code sample generate 1 form field:

$form->addelement(new element\t_company("", "company", array( "required" => 1, "placeholder" => "*bedrijf:", ))); 

i need read .ini file , based on in .ini generate 1 or more lines of code make form field. .ini file contain thing :

fields[company] = t_company,"","company",1,"*company" 

where t_company identifier generate block of code $form->addelement(new element\t_company( next "" identifier "" in php code next "company" identifier "company" in php code next 1 identifier "required" => 1, in php , last 1 "*bedrijf" identifier "placeholder" => "*bedrijf:", idea on how ?

i tried use foreach construct syntax not working

foreach ($formconfig $elementconfig) {     switch (strtolower($elementconfig['type'])) {     case 'text':         $classname = 'element\t_company';             break;     default:       throw new exception();       break;   }   $formelement = new $classname("", "required", array(      "required" => 1,     "placeholder" => "*bedrijf:",     ));   $form->addelement($formelement); } $form = new form($formconfig); 

this helped me

foreach ($ini_array['form_settings'] $type => $fieldsdata) {          if ($fieldsdata['type'] == 'html'){                 $classname = "pfbc\\element\\{$fieldsdata['type']}";                 $form->addelement(new $classname($fieldsdata['string']                 ));             continue;}          if ($fieldsdata['required'] == true){             $classname = "pfbc\\element\\{$fieldsdata['type']}";             $form->addelement(new $classname($fieldsdata['label'], $fieldsdata['id'], array(             'required' => $fieldsdata['required'],             'placeholder' => $fieldsdata['placeholder'],                 )             ));         }          if ($fieldsdata['required'] == false){             $classname = "pfbc\\element\\{$fieldsdata['type']}";             $form->addelement(new $classname($fieldsdata['label'], $fieldsdata['id'], array(             'placeholder' => $fieldsdata['placeholder'],                 )             ));         }   } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -