Alternative to PHP eval? -


i have code returned script in variable. need execute php code nervous use eval function. here code generated in include file:

/include.php:

$preloadfields .=   '$2 = new kooldatepicker("datepicker");                                                          $2->id="field_2";                                                    $2->scriptfolder = "/koolphp"; 

/main.php

eval($preloadfields); 

even when try run using eval, error:

parse error: syntax error, unexpected '2' (t_lnumber), expecting variable (t_variable) or '$'

is there better / safer way accomplish this? thank in advance!

just don't let include.php generate php code in variable. directly execute it.

$2 = new kooldatepicker("datepicker");                                     $2->id="field_2";                               $2->scriptfolder = "/koolphp"; 

if worried html being generated , outputted screen. don't output using ob_start ob_get_contents ob_end_clean:

ob_start(); $2 = new kooldatepicker("datepicker");                                     $2->id="field_2";                               $2->scriptfolder = "/koolphp"; $generated_html = ob_get_contents(); ob_end_clean(); 

anything piece of php try output screen buffered. later in code use $generated_html variable output wherever want.

(you still need fix invalid variable name)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -