我正在用PHP做模板,在其中搜索{tmp_vars}
并将其替换为HTML。我有一个名为{content}
的变量,它实际上是我要显示的当前页面。
我注意到的是,当{content}
(本质上是此变量中的views / page.php)获得太多的内容时(特别是4095个以上的字符,包括HTML标记,文本,空格,注释,所有内容)在该文件中),我的页面有点中断。我突然发现我的脑袋里出现了一个不需要的<style>…</style>
,而且标题和样式表已经跳入了正文。
当我删除HTML内容中的几个字符以使其少于4096个字符时,所有内容都会恢复原位。
这与我允许在字符串变量之内使用多少个字节有关吗?我希望字符串的范围大于最大4095个字节。
在我的layouts / defaut.php中如何使用{content}
的示例:
<html>
<head>
<!-- Title and links to stylesheets -->
</head>
<body>
{content}<!-- Insert views/page.php here -->
</body>
</html>
在我的controller.php中:
public $vars = [];
private function filterVars ($content)
foreach ($this->vars as $key => $value)
if (!is_array($value))
$content = str_replace("{" . $key . "}", $value, $content);
return $content;
}
public function render ($filename) {
extract($this->vars);
ob_start();
require(ROOT . "Views/" . ucfirst(str_replace("Controller", "", get_class($this))) . "/" . $filename . ".php");
$layout = ob_get_clean();
$layout = $this->filterVars($layout);
$this->set("content", $layout);
}
当{content}
(所以$vars["content"]
)超过4095个字符(我假设有一个第4096个字符,即\0
字符)时,我的标题和样式表跳出了标题,进入身体,而在头部出现以下<style>…</style>
:
<style>._3emE9--dark-theme .-S-tR--ff-downloader{background:rgba(30,30,30,.93);border:1px solid rgba(82,82,82,.54);box-shadow:0 4px 7px rgba(30,30,30,.55);color:#fff}._3emE9--dark-theme .-S-tR--ff-downloader ._6_Mtt--header ._2VdJW--minimize-btn{background:#3d4b52}._3emE9--dark-theme .-S-tR--ff-downloader ._6_Mtt--header ._2VdJW--minimize-btn:hover{background:#131415}._3emE9--dark-theme .-S-tR--ff-downloader ._10vpG--footer{background:rgba(30,30,30,.93)}._2mDEx--white-theme .-S-tR--ff-downloader{background:#fff;border:1px solid rgba(82,82,82,.54);box-shadow:0 4px 7px rgba(30,30,30,.55);color:#314c75}._2mDEx--white-theme .-S-tR--ff-downloader ._6_Mtt--header{font-weight:700}._2mDEx--white-theme .-S-tR--ff-downloader ._2dFLA--container ._2bWNS--notice{border:0;color:rgba(0,0,0,.88)}._2mDEx--white-theme .-S-tR--ff-downloader ._10vpG--footer{background:#fff}.-S-tR--ff-downloader{display:block;overflow:hidden;position:fixed;bottom:20px;right:7.1%;width:330px;height:180px;background:rgba(30,30,30,.93);border-radius:2px;color:#fff;z-index:99999999;border:1px solid rgba(82,82,82,.54);box-shadow:0 4px 7px rgba(30,30,30,.55);transition:.5s}.-S-tR--ff-downloader._3M7UQ--minimize{height:62px}.-S-tR--ff-downloader._3M7UQ--minimize .nxuu4--file-info,.-S-tR--ff-downloader._3M7UQ--minimize ._6_Mtt--header{display:none}.-S-tR--ff-downloader ._6_Mtt--header{padding:10px;font-size:17px;font-family:sans-serif}.-S-tR--ff-downloader ._6_Mtt--header ._2VdJW--minimize-btn{float:right;background:#f1ecec;height:20px;width:20px;text-align:center;padding:2px;margin-top:-10px;cursor:pointer}.-S-tR--ff-downloader ._6_Mtt--header ._2VdJW--minimize-btn:hover{background:#e2dede}.-S-tR--ff-downloader ._13XQ2--error{color:red;padding:10px;font-size:12px;line-height:19px}.-S-tR--ff-downloader ._2dFLA--container{position:relative;height:100%}.-S-tR--ff-downloader ._2dFLA--container .nxuu4--file-info{padding:6px 15px 0;font-family:sans-serif}.-S-tR--ff-downloader ._2dFLA--container .nxuu4--file-info div{margin-bottom:5px;width:100%;overflow:hidden}.-S-tR--ff-downloader ._2dFLA--container ._2bWNS--notice{margin-top:21px;font-size:11px}.-S-tR--ff-downloader ._10vpG--footer{width:100%;bottom:0;position:absolute;font-weight:700}.-S-tR--ff-downloader ._10vpG--footer ._2V73d--loader{animation:n0BD1--rotation 3.5s linear forwards;position:absolute;top:-120px;left:calc(50% - 35px);border-radius:50%;border:5px solid #fff;border-top-color:#a29bfe;height:70px;width:70px;display:flex;justify-content:center;align-items:center}.-S-tR--ff-downloader ._10vpG--footer ._24wjw--loading-bar{width:100%;height:18px;background:#dfe6e9;border-radius:5px}.-S-tR--ff-downloader ._10vpG--footer ._24wjw--loading-bar ._1FVu9--progress-bar{height:100%;background:#8bc34a;border-radius:5px}.-S-tR--ff-downloader ._10vpG--footer ._2KztS--status{margin-top:10px}.-S-tR--ff-downloader ._10vpG--footer ._2KztS--status ._1XilH--state{float:left;font-size:.9em;letter-spacing:1pt;text-transform:uppercase;width:100px;height:20px;position:relative}.-S-tR--ff-downloader ._10vpG--footer ._2KztS--status ._1jiaj--percentage{float:right}</style>
我从未写过任何上述CSS。我不知道它从哪里来。
奇数CSS的最小,可复制示例:(是的,它很短)
<!DOCTYPE html>
<html>
<head>
<title>Odd CSS will appear below title</title>
</head>
<body>
<?php
$contentThatWorks = "This is a string... with a lot of whitespace";
$contentThatDoesNotWork = "This is a string... with a lot of whitespace";
echo $contentThatWorks;
echo $contentThatDoesNotWork;
?>
</body>
</html>