Results 1 to 1 of 1

Thread: Getting started with PHP programming

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator yilmaz's Avatar

    Info

    Getting started with PHP programming

    There are some basic rules and information we need to know before we start coding in PHP, before we move on to the next lessons or examples. Like what we need to do to start coding PHP, what we need to do after we start, and what we need to do after we finish.

    When starting and finishing PHP code

    In order for the codes we will write to be found and processed by the server, we need to put “<?php” at the beginning and “?>” at the end of the PHP codes.


    PHP Code:
    1. <?php
    2. //php codes are written here
    3. ?>
    Everything we write between these two tags is processed by the server as PHP code.

    Semicolon
    In PHP we have to put a semicolon (;) after each command (with some exceptions and parts).
    This is because PHP takes all the code in one line and processes it. It understands that by dividing the code you wrote with semicolons, it moves on to the next command.
    We can perceive this semicolon event as the soldiers saying "okay" when their conversation is over in their radio conversations. The term "ok", denoting the end of the command being said here, is a semicolon in PHP.

    Displaying the results on the screen
    While working in PHP, none of the codes we create or write are sent to the person entering the page. In other words, no one can see the codes we write, they can only see the values ​​we want to print out of the codes.
    To print out a value or result, we use the echo or print statement, but most often the echo statement is used. Sample;
    PHP Code:
    1. <?php
    2. echo "Hello World";
    3. ?>
    Demo: https://www.jdoodle.com/a/5yAn

    When this code runs, only the text Hello World comes out.
    If we do not use echo or print statements in our work, visitors to the page may encounter a blank page.
    Echo literally means to reflect. In other words, it reflects the result of our work in PHP to the users through the codes.

    Adding comments or notes inside the codes

    In the long and dense codes we write, we sometimes need to add some explanations so that we or the people we share our codes with can understand the codes more easily. These notes we will add are not visible when we run the codes and do not affect the codes.
    There are 3 different ways to add notes inside the code in PHP. Two of them are one-line annotation and the other one is multiple-line annotation.
    To add a single line note with a hash (#) sign, it is sufficient to put one hash (#) sign per line. What we write after this mark is perceived as a note, not just that line.
    We can perform the same event by using two slash (//) signs as the square sign works.
    To add notes on more than one line, we start the note range with a slash and an asterisk (/*). Where we want the note range to end, we put an asterisk and a slash (*/) on the contrary. (/* not */) Example usages;

    PHP Code:
    1. <?php
    2. # a one-line comment
    3.  
    4. // this is also a one line comment
    5.  
    6. /* if it is
    7. more than one
    8. one line comment
    9. */
    10.   ?>
    With these basics, you can move on to the next lessons and start messing things up.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •