help with creating a constant

Discussion in 'PHP' started by free, Apr 30, 2006.

  1. #1
    hi there, I need help in creating a constant in php5. I'm following the example in the book. the code is:

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <?php
    define<'greeting', 'hello'>;

    echo '<h1> . greeting . '<h1>;
    ?>
    </body>
    </html>

    the error code I get is

    Parse error: parse error, unexpected ',' in /home/content/f/r/e/freecss/html/aaa-practice-php.php on line 7
     
    free, Apr 30, 2006 IP
    Greg-J likes this.
  2. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #2
    I am not 100% but is it not the same as php4

    
    
    define("constant_name", "constant text");
    
    
    Code (markup):
     
    Danny, Apr 30, 2006 IP
  3. free

    free Banned

    Messages:
    1,154
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well, I do not know PHP4, so Im not sure. Im going straight from the book that I have which a tutorial on php5.
     
    free, Apr 30, 2006 IP
  4. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #4
    well the above is how you define a constant in all previous versions of PHP. They wouldn't have changed it so just try that out
     
    Danny, Apr 30, 2006 IP
  5. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #5
    I just confirmed on php.net that a constant is defined the same as in previous versions so your constant would be.

    
    define('greeting', 'hello');
    
    echo "<h1>".greeting."</h1>";
    
    Code (markup):
     
    Danny, Apr 30, 2006 IP
  6. free

    free Banned

    Messages:
    1,154
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I see what I'm doing wrong. I used paranthesis greater than symbols instead of paranthesis in the first line of code. in the second line of code, I didn't surround the heading tags with " on both sides.

    thanks

    btw, if you don't me asking, where did you go on php.net to find that?

    again thanks
     
    free, Apr 30, 2006 IP
  7. free

    free Banned

    Messages:
    1,154
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #7
    retype: mods please delete. thanks
     
    free, Apr 30, 2006 IP
  8. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Go to php.net and in the 'search for' box type 'constant'.

    Alternatively, php.net has a great URL heirarchy. If you know a function name, for example, go to http://php.net/functionname and it will send you straight to it...
     
    TwistMyArm, May 1, 2006 IP