我尝试输出字符串以进一步创建HTML文件,但我无法弄清楚如何使字符串正常工作。没有功能的部件工作正常,但这些功能不起作用......
我的代码:
$stringData = "";
$stringData .= "
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' dir='ltr' lang='cs-cz' xml:lang='cs-cz'>
<head>
<link rel='stylesheet' type='text/css' href='out_styl.css'>
<link rel='stylesheet' type='text/css' href='reset.css'>
<meta http-equiv='content-type' content='text/html; charset=UTF-8' />
</head>
<body>
<div class='stranka'>
<div class='part'>
<h1>Denní nabídka - pondělí</h1>
";
$stringData .= jout("0,2 l", vp_u($dat_po, "pol", "nazev"), vp_u($dat_po, "pol", "cena") . ",-");
$stringData .= "<span>Menu 1.</span>";
$stringData .= jout("0,2 l", vp_u($dat_po, "pol", "nazev"), "");
$stringData .= jout(vp_u($dat_po, "hlj", "gramaz") . " g", vp_u($dat_po, "hlj", "nazev"), vp_u($dat_po, "hlj", "cena") . ",-");
$stringData .= "<span>Menu 2.</span>";
$stringData .= jout("0,2 l", vp_u($dat_po, "pol", "nazev"), "");
$stringData .= jout(vp_u($dat_po, "hld", "gramaz") . " g", vp_u($dat_po, "hld", "nazev"), vp_u($dat_po, "hld", "cena") . ",-");
$stringData .= "<span>Menu 3.</span>";
$stringData .= jout("0,2 l", vp_u($dat_po, "pol", "nazev"),"");
$stringData .= jout(vp_u($dat_po, "hlt", "gramaz") . " g", vp_u($dat_po, "hlt", "nazev"), vp_u($dat_po, "hlt", "cena") . ",-");
$stringData .= "
</div>
</div>
</body>
</html>
";
感谢您的帮助
答案 0 :(得分:0)
试试这个。
ob_start()
和ob_get_clean()
之间的任何内容都不会显示在浏览器中。相反,它可以存储在变量
<?php
ob_start();
?>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' dir='ltr' lang='cs-cz' xml:lang='cs-cz'>
<head>
<link rel='stylesheet' type='text/css' href='out_styl.css'>
<link rel='stylesheet' type='text/css' href='reset.css'>
<meta http-equiv='content-type' content='text/html; charset=UTF-8' />
</head>
<body>
<div class='stranka'>
<div class='part'>
<h1>Denní nabídka - pondělí</h1>
<?php echo jout("0,2 l", vp_u($dat_po, "pol", "nazev"), vp_u($dat_po, "pol", "cena") . ",-"); ?>
<span>Menu 1.</span>
<?php echo jout("0,2 l", vp_u($dat_po, "pol", "nazev"), ""); ?>
<?php echo jout(vp_u($dat_po, "hlj", "gramaz") . " g", vp_u($dat_po, "hlj", "nazev"), vp_u($dat_po, "hlj", "cena") . ",-"); ?>
<span>Menu 2.</span>
<?php echo jout("0,2 l", vp_u($dat_po, "pol", "nazev"), ""); ?>
<?php echo jout(vp_u($dat_po, "hld", "gramaz") . " g", vp_u($dat_po, "hld", "nazev"), vp_u($dat_po, "hld", "cena") . ",-"); ?>
<span>Menu 3.</span>
<?php echo jout("0,2 l", vp_u($dat_po, "pol", "nazev"),""); ?>
<?php echo jout(vp_u($dat_po, "hlt", "gramaz") . " g", vp_u($dat_po, "hlt", "nazev"), vp_u($dat_po, "hlt", "cena") . ",-"); ?>
</div>
</div>
</body>
</html>
<?php
$stringData = ob_get_clean();
?>
关于ob_start();的问题