Is inline HTML valid inside a PHP function?

Is the next valid php?

<?php function a($a) { ?> <p><?=$a?></p> <?php } ?> 

(I know this is not a good idea, I just want to know if this is possible.)

+4
source share
4 answers
 <?php function a($a) { ?> <p><? echo $a?></p> //echo variable content // <? ?> is allowed only if you have **Enabled short_tages in php.ini file** <?php } ?> 

Include short_tages in php.ini file

 <? $a="stackoverflow"; function a($a) { ?> <p><?= echo $a?></p> <? } a($a); ?> 

If you try to run this program using <?= , This will not allow it to give you an error

 Parse error: syntax error, unexpected T_ECHO <?= is not allowed in php for tags <? is allowed if Set short_open_tag=On in php.ini 
+4
source

If short_open_tags are included, yes, it is possible.

+2
source

Yes it is possible. It seems you could easily test this though :) Also try to avoid using <? use <?php - it always works and does not rely on short_tags included in php.ini

+2
source

I think this is not a commonly used format and does not follow the paradigm of writing functional code. In addition, adding dynamic lines to the long embedded html will eventually include more built-in echo calls, which are slower than saving, saving the line and simply adding dynamic content, followed by one echo / print

+1
source

All Articles