Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End why does this work?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #28695
    kloy
    Member

    I’m going to ask a strange question. I’m using this code and it works, but I don’t understand why.
    I’m new to php, and am just learning the syntax. This syntax looks wrong to me….but it works.
    I ask because I’m trying to write another conditional statement and using this as a model…

    What I don’t understand is…why is ?> at the beginning and<?php at the end of the internal statements?

    Code:
    #74011
    Democritus
    Member

    It’s just closing the php interpreter to spill out some html, and then reopening it.

    If you don’t know how code works, just play with it. For example, get rid of all the php start and stops. Then, put all the html tags in something like this:

    echo "<html_tags>Go in double quotes</html_tags";

    The only way to learn to code is to experiment.

    #74014

    Breaking that snippet down, here’s a pseudo-code version. Opening and closing PHP tags, <?php and ?>, need to be included around everything that is php code, so the server understands how to process it correctly:

    Code:

    … normal html code here… (only shows up if the current page is the home page)

    … more normal html code… (only shows up if the current page is not the home page)

    http://www.w3schools.com/php/php_if_else.asp

    Viewing 3 posts - 1 through 3 (of 3 total)
    • The forum ‘Back End’ is closed to new topics and replies.