我想清除其他内容,并用不同的内容重写整个页面。
我有:
网主页:
<?php
include("script.php");
?>
//blah blah, some pre-coded content
的script.php
<?php
if(preg_match('/(?i)msie [1-8]/',$_SERVER['HTTP_USER_AGENT']))
{
// code to replace everything that is pre-coded in the mainpage
// and include the new content
include("replacement.php");
}
?>
我的问题是,如何删除所有以前的内容以覆盖php中的新内容?
我正在寻找类似的东西(但使用PHP):
Javascript:
<script>
document.body.innerHTML = "";
</script>
总结一下:
我在寻找什么?:如何清除页面中的所有内容,并重写新内容。使用 PHP
答案 0 :(得分:3)
如果我理解正确,你需要删除php生成的输出:
ob_start(); //Start buffering
echo "Old content, will not be shown" ;
ob_end_clean(); //Erase the buffer
echo "New content, will be shown" ;
答案 1 :(得分:0)
您无法清除输出,因为您将其直接发送到网络服务器,而网络服务器可能已将其发送给客户。
因此,您应该只输出一些东西,而不是覆盖,而您实际上想要输出。您可以通过简单的ìf
和else
逻辑来实现此目标。
另请参阅输出缓存:
答案 2 :(得分:0)
我想这就是你想要的
ob_start();
echo "Hello world";
if(preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT'])){
ob_clean();
echo "Hello Kitty";
}
ob_get_contents();
但是,在我看来,最好根据浏览器进行切换,而不是使用输出缓冲ID,这是不必要的。