Import HTML As String With PHP Vars -
i've got ajax call returning html. html created , returned in function so:
function return_html(){ $title = 'my form'; $returnobject = array(); $returnobject['html'] = ' <form> <h1>' . $title . '</h1> <input type="text" name="title"/> </form> '; return json_encode($returnobject); }
what i'd write .php file of html , vars in this...
<form> <h1><?php echo $title ?></h1> <input type="text" name="title"/> </form>
and in function import file string vars set sorta this:
function return_html(){ $title = 'my form'; $returnobject = array(); $returnobject['html'] = my_file_as_string_but_with_vars_replaced('formfile.php'); return json_encode($returnobject); }
thoughts?
perhaps
function return_html() { $title = 'my form'; ob_start(); require 'formfile.php'; $returnobject = array('html' => ob_get_clean()); return json_encode($returnobject); }
Comments
Post a Comment