Replacing {{string}} within php file

前端 未结 6 2119
栀梦
栀梦 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:29

    no, don't include for this. include is executing php code. and it's return value is the value the included file returns - or if there is no return: 1.

    What you want is file_get_contents():

    // Here it is safe to use eval(), but it IS NOT a good practice.
    $contactStr = file_get_contents('templates/contact.php');
    eval(str_replace("{{newsletter}}", $newsletterStr, $contactStr));
    

提交回复
热议问题