Is it not possible to exit PHP and use HTML inside a PHP loop like so?
[code]
<?php foreach($categories as $category) { ?>text
<?php } ?>[/code]Thank you.
Is it not possible to exit PHP and use HTML inside a PHP loop like so?
[code]
<?php foreach($categories as $category) { ?>text
<?php } ?>[/code]Thank you.
What happened when you tried it?
Sorry @r937
You can use echo or print() to ouput html. Doing that isn’t going to show anything.
[quote=“RyanReese, post:2, topic:109942”]
What happened when you tried it?[/quote]
i love you, man, thanks
You can however include a file in the foreach loop and then have your HTML get outputted through that include. Also I believe it’s possible to do it your way. I’m doing it right here on my sample foreach and it’s working fine. No errors, nothing. I don’t even have error_logging turned off.
If you are having a problem and nothing is being outputted, I’m guessing it has to be your $categories variable. Is it an array?
I prefer Heredoc or Nowdoc, two syntaxes that replace double-quoted and single-quoted strings respectively
Heredoc:
echo <<< EOT
text
EOT;
Nowdoc:
echo <<< 'EOT'
text;
EOT;
IMHO, with heredoc and nowdoc the script would look better than with “<?php } ?>”.
You can use echo or print() to ouput html. Doing that isn’t going to show anything.
That statement is definitely wrong. You can end PHP and output HTML, as long as you then use PHP again to close your loop. I have done it or seen it done countless times in loose file PHP projects.
However, as others have said, there are methods that will probably both look better and might function better for what you need, especially if you’re just outputting a small amount of basic HTML.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.