I am here in search for a new method. I have defined the value of $SHOW_REALTIME_DATA_BUTTON_LABEL
in another php file like this:
english.php(file name)
define("SHOW_REALTIME_DATA_BUTTON_LABEL","Select realtime data");
...and I want to display that value in another file inside the echo statement like this:
echo '<a class="'.$class1.'" href="'.$link1.'"><span>'.$SHOW_REALTIME_DATA_BUTTON_LABEL.'</span></a> <br>';
In brief, I have to echo the value 'Select realtime data' in between spans.
Simply remove $
from it. This is what you should have:
echo '<a class="'.$class1.'" href="'.$link1.'">
<span>'.SHOW_REALTIME_DATA_BUTTON_LABEL.'</span></a> <br>';
Try this
<span><?php echo SHOW_REALTIME_DATA_BUTTON_LABEL?></span>
Defined things not need $ symbol in php
Drop the bucks. PHP defines don't have a $ at the beginning.
Everybody is showing you the fish, but better learn about the use of constants in PHP:
<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
?>
When you use define you are creating a constant, which is good to use when you have things that are constant. An example of predefined constant is the value of PI:
echo M_PI; // 3.1415926535898
These are things that are not changing during the execution of your script. Another good example is:
define("MONTHS", 12); // months in year
define("WEEK", 7); // days in weeek
You dont need to use a $ sign for constants, only for variables. And remember that the is recommended to use CAPITALS for constants but not mandatory.
this definitely should be
<a class="<?=$class1?>" href="<?=$link1?>">
<span><?=SHOW_REALTIME_DATA_BUTTON_LABEL?></span>
</a><br>
However, I wouldn't use constants for the internationalization but rather arrays or gettext
Also, a constant name looks oversized while words "show" and "label" unnecessary. realtime_data_button
looks better to me