+3 html...">

Php and EOT constants

Is it possible to display php EOT constants? eg:


<?
  define('Hey', "HellO");
  echo
<<<EOT
Hey
EOT;
?>

+3
source share
3 answers

I found a solution to be able to display HTML / PHP and even PHP constants, and then store the extended string in a variable:

my_file.php



Welcome back <?=$User -> get_display_name(); ?>!



index.php


<?

  define('HEY', "Welcome to my website!");

  ob_start(); ?>
  <div id=welcomeBox>
  <? if($User -> is_real()): ?>
  <? require_once("my_file.php"); ?>
  <? else: ?>
  <?=HEY; ?> Click <a href=JavaScript:SignUp()>here</a> to sign up!
  <? endif; ?>
  </div>
  <?
  $page_body = ob_get_contents();
  ob_end_clean(); ?>
  <div>
    Aye
  </div>
<?=$page_body;?>



If the user is real, the output will look something like this:


  <div>
    Aye
  </div>
  <div id=welcomeBox>
    Welcome back Johnny Cash!
  </div>


Otherwise, he would say:


  <div>
   Aye
  </div>
  <div id=welcomeBox>
    Welcome to my website! Click <a href=JavaScript:SignUp()>here</a> to sign up!
  </div>


0
source

Nope. Just like you cannot display a constant inside a string. There are only two real ways to access a constant value:

Directly in the code:

$foo = Hey;

Or using constant:

$foo = constant('Hey');
+3
source

, heredoc (< < <) , PHP. , .

PHP, . , .

+1

Source: https://habr.com/ru/post/1771729/


All Articles