Labels

Tuesday, 18 October 2016

PHP DATA TYPES

Variables can store data of different types, and different data types can do different things.

PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource 

PHP String

A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single or double quotes:

<?php
$x = "Hello world!";
$y = 'Hello world!';

echo $x;
echo "<br>";
echo $y;
?>


PHP Integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:

An integer must have at least one digit
An integer must not have a decimal point
An integer can be either positive or negative
Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)

In the following example $x is an integer. The PHP var_dump() function returns the data type and value:

<?php
$x = 5985;
var_dump($x);
?>


PHP Float

A float (floating point number) is a number with a decimal point or a number in exponential form.
In the following example $x is a float. The PHP var_dump() function returns the data type and value:
<?php
$x = 10.365;
var_dump($x);
?>

PHP Boolean

A Boolean represents two possible states: TRUE or FALSE.
$x = true;
$y = false; 


PHP Array

An array stores multiple values in one single variable.
In the following example $cars is an array. The PHP var_dump() function returns the data type and value:

<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?> 

Monday, 10 October 2016

Mad about computer


Getting started with php

Image result for php










  


What is PHP? 

 PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. 
PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.


        PHP is an acronym for "PHP: Hypertext Preprocessor"

        PHP is a widely-used, open source scripting language

        PHP scripts are executed on the server

        PHP is free to download and use

        PHP file has the extension ".php"



 What Can PHP Do?



    PHP can generate dynamic page content

    PHP can create, open, read, write, delete, and close files on the server

    PHP can collect form data

    PHP can send and receive cookies

    PHP can add, delete, modify data in your database

    PHP can be used to control user-access

    PHP can encrypt data





With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

PHP has the following advantages:


    PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)

    PHP is compatible with almost all servers used today (Apache, IIS, etc.)

    PHP supports a wide range of databases

    PHP is free. Download it from the official PHP resource: www.php.net

    PHP is easy to learn and runs efficiently on the server side



How can i get started?


To setup php on your PC, you need to perform the following steps:

                Get a software tool for localhost server to run on your pc

                Install and make some connections

                Test your connections

                Start running php script on your pc



To get a software and start running php on your pc, firstly Xamp or Wamp is mostly used software to run php script and here we are going to use wampServer to test and run our php script. To get wampserver click on the link below, locate and click the download option.



INSTALLING:

After downloading, double click to start installing, follow the guides and installation directions to finish installing.


TEST YOUR CONNECTIONS:

After installing, type 127.0.0.1 into your url browser, if it does display a page like the image below with no error message, that means you are good to go, else you need to make some more modifications in the php.ini file, search or find localhost then add a four figure to it.  e.g localhost:8080
Now restart your server and re-run the code.







START YOUR FIRST PHP SCRIPT:

To start coding with php on your machine, type the following code below into a notepad and save it as hello.php into the www root directory folder, from the Local Disk (C:) you will see wamp folder, open the it and save the hello.php into the www folder. Now go back to your browser and type localhost/hello.php it should now display "Hello World" if you set up your environment properly, no error message would be thrown.



<!DOCTYPE html>

<html>

<body>


<?php       

                $Hello = "Hello world.";

      echo $Hello;

  ?>

</body>

</html>





After running the code, it should display "Hello world" on your browser.