开发者

PHP placement problem

I am calling this function halfway down the page:

    <div id="leftArea">
        <?php
        if (isset($id)){
            single($id);
        }
        ?>
    </div>

The problem is i want use some of the output in the meta tags in the <head>, whats the best way to approach t开发者_运维问答his?

EDIT:

The single function, takes the $id and echo's the data straight to the page, exactly where it is. In the DIV leftArea. But i want to take one of the rows from the DB and insert it into the META tags at the top


Copy the code into the <head> section.


Redesign your System

The best method is to create a class that manages your html page for you, example:

$Page = new HTMLPage("My Page",HTMLPage::Strict);

$Page->addScript("....");
$Page->addScript("....");
$Page->addScript("....");

$Page->addStyle("....");
$Page->addStyle("....");
$Page->addStyle("....");

$Page->SetBody($MyTemplate);

$Page->send();

this way though out your functions you can do

function myfunc()
{
    global $Page;
    $Page->addScript("....");
}

the main point here is you should build your document up before sending it to the browser, this way you still have control over the content no matter where your code is executing from.

on the final send method you build your content up, and then push the content via echo, and then exit directly. (all processing should be done prior to output to manage errors)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜