1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Seattle, Wa USA
    Rep Power
    Hi everyone-

    Trying to deal with globals and am failing, please help! Here is an example of my not-so-ideal code which, isn't working so well.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><?
    function printc($text,$color="000000")
    global $color;
    print("<Font color="$color">$text</font>");

    print "$color";
    printc ("this is 000000");

    print "$color";
    printc ("this is $color text", "aaccaa");


    I do not understand how to get $color to print without using the printc function that I created. Please help!

  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    If I understand what you are trying to do correctly, this should work:<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><?php
    function printc($text, $color)
    print "<font color="#$color">$text</font>";

    $color = "aaccaa";

    printc("this is $color text", $color);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Ontario, Canada
    Rep Power
    You're going about it a little off-key... If I understand your dilemna, you're having problems with global variables... Try this:

    $color = "#acacac"; // whatever you want here
    function printc($text) {
    global $color;
    echo "<FONT color="$color">$text</FONT>";

    You have to declare the variables BEFORE you call or declare the function, so PHP knows what to look for when it parses the code.

    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

Similar Threads

  1. global variables + oscommerce
    By gbow in forum PHP Development
    Replies: 2
    Last Post: February 12th, 2004, 03:08 AM
  2. global variables = Off
    By tricky_kid in forum PHP Development
    Replies: 1
    Last Post: November 4th, 2003, 08:16 AM
  3. Function programming global var problem
    By beardo in forum PHP Development
    Replies: 3
    Last Post: February 19th, 2003, 04:03 AM
  4. global variable in switch???
    By ecastanedo in forum PHP Development
    Replies: 7
    Last Post: November 21st, 2001, 12:35 PM
  5. since nobody answers me, got a new quesition.
    By seanma in forum MySQL Help
    Replies: 7
    Last Post: August 26th, 2000, 11:47 AM

IMN logo majestic logo threadwatch logo seochat tools logo