Posts

Showing posts with the label PHP

PHP Operators

 There are following types of operator in PHP: Arithmetic operators Assignment operators Comparison operators Increment/Decrement operators Logical operators String operators Array operators Conditional assignment operators Arithmetic operators: + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y ** Exponentiation $x ** $y Result of raising $x to the $y'th power Assignment operators: x = y x = y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x = x - y Subtraction x *= y x = x * y Multiplication x /= y x = x / y Division x %= y x = x % y Modulus Comparison operators: == Equal $x == $y Returns true if $x is equal to $y === Identical $x === $y Returns true if $x is equal to...

PHP Constants

 A PHP cosntant is an identifier  which value cannot be changed during the script. A valid constant name start with letter or underscore(no other special character or number). Syntax: define(name, value, case-insensitive) Example: <?php define("GREETING", "Welcome to W3Schools.com!"); echo GREETING; ?> Array constant in PHP: <?php define("cars", [   "Alfa Romeo",   "BMW",   "Toyota" ]); echo cars[0]; ?> Constants are global in PHP you can use it anywhere see below example: <?php define("GREETING", "Welcome to W3Schools.com!"); function myTest() {   echo GREETING; }   myTest(); ?>

PHP Math Functions

 Php has some predefined math functions to calculation mathematics problems. Some of them are listed below: 1) Php pi() function: <?php echo(pi()); // returns 3.1415926535898 ?> 2) Php min() & max() function:  <?php echo(min(0, 150, 30, 20, -8, -200));  // returns -200 echo(max(0, 150, 30, 20, -8, -200));  // returns 150 ?> 3) Php abs() function:  <?php echo(abs(-6.7));  // returns 6.7 ?> 4) Php sqrt() function:  <?php echo(sqrt(64));  // returns 8 ?> 5) Php round() function:  <?php echo(round(0.60));  // returns 1 echo(round(0.49));  // returns 0 ?> 6) Php rand() function:  <?php echo(rand()); ?> For complete math functions you can visit w3schools.com website. 

Data Types in PHP

  PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource There are some examples of data types in PHP, you can use it understand the concept: String <?php $x =  "Learn PHP By RK" ; $y =  'Learn Wordpress By RK' ; echo  $x; echo   "<br>" ; echo  $y; ?> Integer <?php $x =  9685 ; var_dump($x); ?> FLOAT <?php $x =  18.635 ; var_dump($x); ?> Boolean $x = true; $y = false; Array <?php $cars =  array ( "Iron Man" , "Hulk" , "Thor" ); var_dump($cars); ?> Object In the following example car in Class having properties color and model. <?php class  Car {    public  $color;    public  $model;    public   function  __construct($color, $model) {      $this->color = $color;     $this->model = $model;    }    public   fun...

How to install and setup PHP?

  What Do I Need? To start using PHP, you can: Find a web host with PHP and MySQL support Install a web server on your own PC, and then install PHP and MySQL Use a Web Host With PHP Support You can simply download Xampp or Wampp Server on your PC. Just Search "Download Xampp for windows 7" (Or whatever your OS windows 7, Windows 10 etc). Click any site on google and download xampp server. Install it and setup. You can setup Xampp by finding any Video on Youtube. First program in PHP After successful installation of Xampp Server on your PC, Go to C://Xampp/htdocs Create here any folder and then create a new file with .php extention. For example crate a folder named 'TEST' and then enter to this folder. Test create a file 'test.php' with the code written below: <?php $txt =  "PHP" ; echo   "I love  $txt! " ; ?> Now go to your browser and open your file with localhost/YourFfolderName/YourFileName.php For Example localhost/test/test.ph...

Brief Intro of PHP

  What You Should Already Know Before you continue you should have a basic understanding of the following: 1) HTML 2) CSS 3) JAVASCRIPT What is PHP? 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 What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code is executed on the server, and the result is returned to the browser as plain HTML PHP files have 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 an...

Learn Php

Image
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 7 is the latest stable release. Example: <!DOCTYPE html> <html> <body> <?php echo "Hello RK. This is PHP example."; ?>  </body> </html>