html - Update php variable in head while writing in footer -


When I am creating my page, then I am updating the variable $ links Css refers to the link which the page's & lt; Head & gt; Will be placed in the section.

But when I am at the bottom of the page, I have found my last value for $ links , instead of the end of the page & lt; Head & gt; I want to be written in .

I have tried it with str_replace , but he writes it down below ..

php looks like this:

  & lt; Top & gt; & Lt ;? Php echo $ links; ? & Gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php included 'gallery.php'; $ Link = & Lt; Link type = "text / css" href = "/ css / lightbox.css"> ? & Gt; & Lt; / Body & gt;    

I agree with the comment about separation of logic, ideal situation When you write pages, you have all the information gathered beforehand ...

However, as a quick improvement does not involve much refactoring, you can use output buffering Are:

  & lt ;? Php ob_start (); ? & Gt; & Lt; Top & gt; PLACEHOLDER_LINKS & lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php included 'gallery.php'; $ Link = & Lt; Link type = "text / css" href = "/ css / lightbox.css"> ? & Gt; & Lt; / Body & gt; & Lt ;? Php $ html = ob_get_clean (); $ Html = str_replace ("PLACEHOLDER_LINKS", $ link, $ html); $ Echo echo;   

Although I'm suggesting the MVC pattern and implementing it in the frameworks ... it can save many headaches like this;)

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -