J'ai un appel ajax retournant du code HTML. Le code HTML est créé et retourné dans une fonction comme ceci:Importer HTML en tant que chaîne avec PHP Vars
function return_html(){
$title = 'My Form';
$returnObject = array();
$returnObject['html'] = '
<form>
<h1>' . $title . '</h1>
<input type="text" name="title"/>
</form>
';
return json_encode($returnObject);
}
Ce que je voudrais faire est d'écrire un fichier .php avec tout mon html, VARs comme ça ...
<form>
<h1><?php echo $title ?></h1>
<input type="text" name="title"/>
</form>
puis dans mon importation de fonction ce fichier comme une chaîne avec les vars définies sorta comme ceci:
function return_html(){
$title = 'My Form';
$returnObject = array();
$returnObject['html'] = my_file_as_string_but_with_vars_replaced('formFile.php');
return json_encode($returnObject);
}
pensées?
Quelle est votre question? –
Sonne que vous voulez construire un moteur de template. – Hamish
@hamish, quelque chose de similaire, bien que sur une très petite échelle. –