efficacious Posted May 15, 2011 Share Posted May 15, 2011 Does anyone know how to echo a defined constant without using concatenation? something like <?php define("CONST", "VALUE"); echo <<<END Some html and my Const = CONST END; ?> This works but I want the var to be const <?php $CONST = "VALUE"; echo <<<END Some html and my Const = $CONST END; ?> Thanks for your replies Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/ Share on other sites More sharing options...
fugix Posted May 15, 2011 Share Posted May 15, 2011 What exactly do you mean by you want the var to be constant without concatenation? Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215783 Share on other sites More sharing options...
Zurev Posted May 15, 2011 Share Posted May 15, 2011 I believe you'd have to concatenate it...like echo "This is my constant". CONSTANT; But what's the big deal of having to use concatenation? Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215785 Share on other sites More sharing options...
efficacious Posted May 15, 2011 Author Share Posted May 15, 2011 I have the values plugged into HTML that gets included and echoed out and I don't want ppl who may have to edit the html later to have to deal with concatentation.. Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215787 Share on other sites More sharing options...
fugix Posted May 15, 2011 Share Posted May 15, 2011 You can also encase the var in curly brackets instead of concatenation. Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215790 Share on other sites More sharing options...
efficacious Posted May 15, 2011 Author Share Posted May 15, 2011 You can also encase the var in curly brackets instead of concatenation. could you show an example..plz Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215793 Share on other sites More sharing options...
Zurev Posted May 15, 2011 Share Posted May 15, 2011 Right, you can for variables..but not constants: $variable = 'Hello World'; echo "Guess what? {$variable}"; // Guess What? Hello World Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215803 Share on other sites More sharing options...
efficacious Posted May 15, 2011 Author Share Posted May 15, 2011 I suppose its not completely necessary to use a constant but it would be ideal Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215806 Share on other sites More sharing options...
fugix Posted May 16, 2011 Share Posted May 16, 2011 yes i would like to know why you need to use a constant here Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215878 Share on other sites More sharing options...
efficacious Posted May 16, 2011 Author Share Posted May 16, 2011 i was offbase with the constants I think but after looking at the how phpbb handled their html files I made my own light weight version of it. Its working much better now.. I ended up making a template class that compiles w.e html documents previously set to a string then that string is returned and evaluated then just printed out. I have gotten it to succesfully build an HTML template with php variables and displayed with values. The value i had orginally intended to echo as a constant I changed to a regular variable. Thanks for your replies all, they were all helpful. Quote Link to comment https://forums.phpfreaks.com/topic/236487-working-with-constants/#findComment-1215908 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.