-2

I cannot figure out what the ?> <? syntax is doing in this code. I have searched the php syntax page and this is not an opening or closing tag nor a short open tag. The code will not compile without it and I am getting a strange coloring in the curly brackets that follow.

if(isset($_POST)){?>
            <form method="POST" action="Form_Index.php">
            User <input type="text" name="userTwo"></input><br/>
            Pass <input type="password" name="passTwo"></input><br/>
            <input type="submit" name="submit" value="Go"></input>
            </form>
    <?}
CherryDT
  • 25,571
  • 5
  • 49
  • 74
Bryan
  • 13
  • 2
  • 1
    `?>` is **always** the closing tag for the PHP context. `` is a short-open-tag and should be avoided for portability in favour of `` and `` is just static HTML that will be added directly to the output buffer – Phil Jun 29 '20 at 23:16
  • The manual page you're looking for is here ~ https://www.php.net/manual/language.basic-syntax.phptags.php – Phil Jun 29 '20 at 23:19
  • This is not correct. If you look closely you will see the code has ?> not . If I switch the ? and the > around the code does not work. Also, I I use – Bryan Jun 30 '20 at 03:31
  • Sorry, I'm not following. Your code has some PHP, an opening brace `{`, then the closing `?>`, then some static HTML, then the open-short-tag `` and then finally `}`. If it helps you understand it better, think of it like `if (isset($_POST)) { echo '
    ...
    '; }` where the content between `?>` and `` replaces the `echo`
    – Phil Jun 30 '20 at 03:50
  • No worries, so here is the deal, the code works... however if I use " tag the code does not work. It is super basic and I get it, an undergrad can probably answer the question. I've been a professional programer for over 10 years, php is a newish syntax to me. I just want to understand what is happening here. Why is my server throwing a fit? works... – Bryan Jul 01 '20 at 07:12
  • What's the error? If you replace ` }` with ` – Phil Jul 01 '20 at 07:58
  • Parse error: syntax error, unexpected '<' I've played around with adding and deleting closing braces, adding and deleting short-open-tags. The code wants to work one way, it's just that way is not in keeping with what I'm used to seeing. It's not a big deal, I just saw this as an opportunity to learn some fundamentals. Thanks for your help. – Bryan Jul 02 '20 at 04:11
  • Ah, I think I see. When you use ` – Phil Jul 02 '20 at 04:14
  • You sir, are a hero; the whitespace did it. Thank you for solving this question. – Bryan Jul 04 '20 at 20:58

1 Answers1

-1

Your PHP code lives between <?php and ?>

So the ?> means that PHP stops there, and HTML starts.

<? Is just a short notation for <?php.

To add to the confusion, the ?> close tag is optional at the end of a file.

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122