Php as a tag in html form

I am trying to loop through a csv file that has a number of file names that I want to display in a form. The user checks the selections and then I display the contents as a single page. I read a post that showed how to list the html tags and insert the PHP tag to read the variable. If the pho parser doesn’t care whether I exit and enter PHP and html tags, can I simply exit PHP to do the html with a short break to do PHP variables and then return to PHP to complete my loop? I believe the alternative is I stay in PHP and echo the html tags using the escape character to trap the double quotes normally in the checkbox tag?

In general, you should not echo large blocks of static html. In this case, you should drop out of php mode and put the html inline.

When you have a mix of php/html, I usually go with a majority rule. If there is more html, drop out of php mode, put the html inline, then back into php mode to echo a variable. If there is more php than html, echo the html.

Note: php’s short-echo tag <?= will save you typing, and you don’t need the ; on the end of php statements when they are followed by a closing ?> tag, so <?=$var?> is the simplest syntax you can use to echo a php variable.

Don’t do that. Just use single-quotes in the html.

Thanks. If I am within the brackets of a loop in PHP , can I stop PHP, enter the HTML tags, and then return to PHP complete the loop?

Yes. You could also just try it to confirm for yourself that it works.

Sponsor our Newsletter | Privacy Policy | Terms of Service