How to RUN PHP Code

 

Home || News || Stories || Installer ||


 How to use XAMPP to run PHP code

A PHP file typically contains HTML tags as well as PHP scripting code. A simple PHP example is quite simple to make. To do so, make a file and fill it with HTML tags and PHP code, then save it with the.php extension.

Note that all PHP statements terminate in a semicolon (;).

The php tag contains all PHP code. It begins with? and ends with php? >. The PHP tag syntax is as follows:



<?php  
//your code here  
?>  



Let's look at a simple PHP example where we use the PHP echo command to write some text.


<!DOCTYPE>  
<html>  
<body>  
<?php  
echo "<h2>Hello First PHP</h2>";  
?>  
</body>  
</html>  


Output:

Hello First PHP


How to use XAMPP to run PHP scripts

PHP is a common backend programming language that can be run with XAMPP. PHP scripts can be written with any text editor, including Notepad++, Dreamweaver, and others. These programs save as filename.php in the htdocs folder, with the.php extension.

For instance, p1.php.

Because I'm using Windows, my XAMPP server is located on the C drive. As a result, the htdocs directory will be "C:\xampp\htdocs".





PHP Case Sensitivity

Keywords (such as echo, if, else, while), functions, user-defined functions, and classes are case-insensitive in PHP. All variable names, however, are case-sensitive.

You can see that all three echo statements are equal and legitimate in the example below:

<!DOCTYPE>  
<html>  
    <body>  
        <?php  
            echo "Hello world using echo </br>";  
            ECHO "Hello world using ECHO </br>";  
            EcHo "Hello world using EcHo </br>";  
        ?>  
    </body>  
</html>  

Output:

Hello world using echo
Hello world using ECHO
Hello world using EcHo


Take a look at the example below to see how variable names are case sensitive. Only the second statement in the example below will display the value of the $color variable. Because $color, $ColoR, and $COLOR are all treated as three separate variables:

<html>  
    <body>  
        <?php  
            $color = "black";  
            echo "My car is ". $ColoR ."</br>";  
            echo "My dog is ". $color ."</br>";  
            echo "My Phone is ". $COLOR ."</br>";  
        ?>  
    </body>  
</html>  

Output:

Notice: Undefined variable: ColoR in D:\xampp\htdocs\program\p2.php on line 8
My car is
My dog is black

Notice: Undefined variable: COLOR in D:\xampp\htdocs\program\p2.php on line 10
My Phone is


                                                                                                                




Mga Komento