Announcement

Collapse
No announcement yet.

Including php code in header

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Including php code in header

    I will apologise in advance as I am a php n00b, so please excuse my ignorance.

    I have some php code that I wish to insert into the header template:

    Code:
    <?php
            $open = fopen("http://au.finance.yahoo.com/d/quotes.csv?s=^AORD&m=a&f=sl1d1t1c1ohgv&e=.csv", "r");
            $read = fread($open, 2000);
            fclose($open);
            $read = str_replace("\"", "", $read);
            $read = explode(",", $read);
            $current = $read[1];
            $when = $read[3];
            $move = $read[4];
            $paint = "Red";
            if ($move > 0.001):$paint = "Green"; endif;
            print ("<font size=\"3\" face=\"Arial, Helvetica, sans-serif\"><b>All Ords: <font color=\#2222FF\>$current</b><br><font color=\"$paint\">$move &nbsp<font color=\"black\"> $when</td>"); 
    ?>
    I have heard I need to use the phpinclude_start template... but I read the section of the manual about it but I just can't seem to figure out what I am supposed to do.

    Can anyone please give me the lowdown on how I might get this to work.

    Any advice appreciated!

  • #2
    Are you using 3.0 or 3.5?

    The code you have is fine, except you need to change it slightly (you also do not need the <?php or ?>)

    PHP Code:
    $open fopen("http://au.finance.yahoo.com/d/quotes.csv?s=^AORD&m=a&f=sl1d1t1c1ohgv&e=.csv""r");
    $read fread($open2000);
    fclose($open);
    $read str_replace("\""""$read);
    $read explode(","$read);
    $current $read[1];
    $when $read[3];
    $move $read[4];
    $paint = ($move 0) ? "Green" "Red"#fixed that little bit for you ;)
    $allords "<font size=\"3\" face=\"Arial, Helvetica, sans-serif\"><b>All Ords: <font color=\#2222FF\>$current</b><br><font color=\"$paint\">$move &nbsp<font color=\"black\"> $when</td>"
    unset(
    $read$current$when$move$paint); 
    Now, if you're using 3.0, add that code to your phpinclude_start template.

    If you're using 3.5, youll need to create a hook for global_start and add it there. You can then add the code to that hook.

    All you need to do, is then add $allords to the navbar template where you want it to be displayed.

    Comment


    • #3
      Hi, thanks very, very much for your help... it's appreciated!

      I am using 3.0.8, so do I simply add that code to the phpinclude_start template and then add $allords to the template? How does it know it's $allords... do I need to put "$allords =" and then the code?

      Comment


      • #4
        I think...

        You copy the whole thing an put in php_includes then you take variabale "$allords" and place in the template you where you want to display content.

        Comment


        • #5
          Originally posted by harmor
          I think...

          You copy the whole thing an put in php_includes then you take variabale "$allords" and place in the template you where you want to display content.
          Yes, but how does it know that particular piece of code is $allords?

          How do I assign it as such?

          Comment


          • #6
            Originally posted by Joe Blow
            Yes, but how does it know that particular piece of code is $allords?

            How do I assign it as such?
            That's what your second last line of code does... n'est pas?

            Comment


            • #7
              Originally posted by TCM
              That's what your second last line of code does... n'est pas?
              Ahhhh... thank you kind sir!

              I feel stupid now.

              Comment

              Related Topics

              Collapse

              Working...
              X