I noted on another thread people mentioning mixing HTML and PHP in example would this be bad practice?

	<ul class="times-list">
	 <li><?php echo $res['streetNumber'] . " " . $res['street']; ?></li>
	 <li><?php echo $res['town']; ?></li>
	 <li><?php echo $res['region']; ?></li>
	 <li><?php echo $res['postcode']; ?></li>
	 <li><?php echo $res['phone']; ?></li>	
	</ul>

    I think it's not an issue there, as (at least at that point) you're just using PHP to embed variables. You're effectively in a HTML file using PHP to handle those values. It's when you are jumping back and forth between server-side data manipulation and the application of business logic into bits of HTML and/or JavaScript output that it starts to become clumsy, hard to read, and therefore hard to maintain.

      That code does not look problematic to me. In fact, it looks a lot like a CodeIgniter view file. You might also have some loops in there, too.

      What you want to avoid is extensive PHP (database queries, file system access, complex logic and variable assignments, etc) mixed in with HTML.

        Yeah, can be a tough call. What you're showing is fine and it actually why this tag still exists:

        <?=$foo ?>

        Your alternative is some sort of templating-engine-like structure where PHP does replacement of variables, a la Smarty. That adds its own sort of complexity to your project.

        And what Sneaky & NogDog say is true. I've got quite a bit of technical debt of that nature.

          Oh so this would be a problem long term

          $foo = <xmp>
          
          <?=$foo ?>
          

          because it's deprecated it would for lack of a better term cause trouble

            In some older versions of PHP, the <?= tag can be disabled (along with the <? option), but in later versions of PHP the <?= tag is always enabled, even if <? is disabled.

            <?php echo "This always works."; ?>
            <? echo "This may not work."; ?>
            <?= "This always works, except in older versions, when it may not work"; ?>
            

            🙂

              Haha it seems my ignorance of certain tags seems to have stopped me developing bad habits

                Write a Reply...