目前我有一个使用include
的php页面来显示html页面。
我想要做的是使用调用时收到的php-page变量,并根据此变量将数据投影到html-page的字段中。问题是我似乎无法将变量从php传递给html而不使用html来调用php。
我知道我可以简单地回应一下php-part,但因为我无法直接回到其中一个html-page的div中,所以它最终会将回声置于其开头或结尾处。页。
我想要完成的是html页面在php第一次包含html页面时将php-part加载到其中一个div中。有没有办法做这样的事情?
如果这不可能,那么如何在html页面中使用javascript来使用php文件中的变量?是最好的选择吗?
根据要求提供了一些代码: PHP:
if (filter_input(INPUT_GET, "event", FILTER_SANITIZE_STRING))
{
include "../Html/EventPage.html"; //target page
$temp = filter_input(INPUT_GET, "event", FILTER_SANITIZE_STRING); //get the variable
include "../PHP/Connector.php"; //include the connection page
$value = callFunction(Connect(), $temp); //call connection page and return value
echo "<div class = 'cant select div in html'>" . $value . "</div>"; //echo value in location
}
HTML:
<div id = "dynamic">
this should have the php
</div>
答案 0 :(得分:0)
我假设你使用这样的代码来显示页面:
include('page.html');
更安全的方法是阻止page.html中的评估:
echo file_get_contents('page.html', true);
然后,您可以对内容进行任何字符串修改:
$replacement = 'MY REPLACEMENT';
echo str_replace('<div id="my-div">', '<div id="my-div">' . $replacement, file_get_contents('page.html', true));