PHP Vars ile As String HTML Alma

0 Cevap

Ben bazı html dönen bir ajax arama var. Html şöyle oluşturulan ve bir işlevi döndürdü:

function return_html(){
    $title = 'My Form';
    $returnObject = array();
    $returnObject['html'] = '
                <form>
                    <h1>' . $title . '</h1>
                    <input type="text" name="title"/>
                </form>
    ';

    return json_encode($returnObject);
}

Ne yapmak istiyorum benim html ile tüm bir. Php dosyası yazmak ve bunu böyle vars ...

<form>
    <h1><?php echo $title ?></h1>
    <input type="text" name="title"/>
</form>

ve sonra sorta böyle ayarlandığında değişkenler ile bir dize gibi dosya benim işlevi ithalat:

function return_html(){
    $title = 'My Form';
    $returnObject = array();
    $returnObject['html'] = my_file_as_string_but_with_vars_replaced('formFile.php');   
    return json_encode($returnObject);
}

Düşünceler?

0 Cevap