Jukka Nevalainen Imbera Jukka Nevalainen Imbera - 4 years ago 101
PHP Question

Function in a variable not working

I'm trying to output a string for further creating a HTML file and I can't figure out, how to make the string working. Parts without functions work just fine, but those functions do not work...

My code:

$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>
";


Thanks for help

Answer Source

Try this one.

Anything between ob_start() and ob_get_clean() will not show up in browser. instead it can be stored in a variable

<?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();
?>

Question on ob_start();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download