# Php as a tag in html form

**URL:** <https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003>\
**Category:** Beginners - Learning PHP\
**Created:** [February 1, 2024, 9:25pm UTC](https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003 "2024-02-01T21:25:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hotspringsrus](https://www.phphelp.com/letter_avatar_proxy/v4/letter/h/d6d6ee/32.png) [@Hotspringsrus](https://www.phphelp.com/u/Hotspringsrus)\
**Post date:** [February 1, 2024, 9:25pm UTC](https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003/1 "2024-02-01T21:25:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [February 1, 2024, 11:41pm UTC](https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003/2 "2024-02-01T23:41:19Z")

</div>

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.

> [@Hotspringsrus](#):
>
> using the escape character to trap the double quotes

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

---

<div class="post-metadata">

**Author:** ![Hotspringsrus](https://www.phphelp.com/letter_avatar_proxy/v4/letter/h/d6d6ee/32.png) [@Hotspringsrus](https://www.phphelp.com/u/Hotspringsrus)\
**Post date:** [February 2, 2024, 4:38am UTC](https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003/3 "2024-02-02T04:38:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [February 2, 2024, 4:59am UTC](https://www.phphelp.com/t/php-as-a-tag-in-html-form/36003/4 "2024-02-02T04:59:04Z")

</div>

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