php template replace with array data

0

Hi, I have the following html code in a php file:

<!DOCTYPE html>
<html lang="{lang}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{Title}</title>
    </head>
    <body>
    </body>
</html>

As you will see, I have some words between {lang} or {Title} . I'm saving the php file in a variable:

$vdata = file_get_contents('path/archivo.php');

I have an array in the following way:

 array(2) {
    ["lang"]=>
    string(4) "es_ES"
    ["Title"]=>
    string(7) "Mi Pagina Web"
  }

How can I do the replacement?

    
asked by Francisco Núñez 20.02.2018 в 17:00
source

1 answer

0

Solved: the array is in $Dic

foreach ($Dic as $key => $value) {
    $text = str_replace('{'.$key.'}',$value, $vdata);
}

Although I do not know if it is the best way to do it.

    
answered by 20.02.2018 в 17:18