PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I define a constant in PHP?


It is not actually that common a requirement to define a constant in your PHP code, but when you need to do so you will know about it, so it's useful to know how to go about doing it.

And here is how:

<?php
define
('NAME''Tarquin');
?>


This defines a constant called NAME and assigns it the value of Tarquin. Now assuming you don't ever change your name (well, maybe if you're called Tarquin...) then this would be a possible instance of defining a constant.

How do you access it? Like this:

<?php
echo 'Hello, ' NAME;
?>


It is very important to note that the constant is printed outside of any quotation marks; include it within them and you will just see NAME printed to screen rather than the actual value of the constant.



Comment on this Question and Answer >>>

ASK A QUESTION

More other PHP Questions

What is the difference between the while and do while loops?

Can I spellcheck my text using PHP?

how can i put the value 1 or 0 into checkbox if we checked then 1 otherwise 0?

Can PHP create PDF files for me?

How do I check if a date entered exists?



Custom Search