Replacing {{string}} within php file

前端 未结 6 2118
栀梦
栀梦 2020-12-08 17:08

I\'m including a file in one of my class methods, and in that file has html + php code. I return a string in that code. I explicitly wrote {{newsletter}} and th

6条回答
  •  星月不相逢
    2020-12-08 17:28

    maybe a bit late, but I was looking something like this.

    The problem is that include does not return the file content, and easier solution could be to use file_get_contents function.

    $template = file_get_contents('test.html', FILE_USE_INCLUDE_PATH);
    
    $page = str_replace("{{nombre}}","Alvaro",$template);
    
    echo $page;
    

提交回复
热议问题