21
PHP Definition: Definition: PHP stands for Personal Home Page. The PHP Hypertext Preprocessor allows web developers to create dynamic content that interacts with databases. PHP applications are normally found on Linux servers and in conjunction with MySQL databases. It provides those servers with functionality similar to that provided to the Windows platform by Active Server Pages technology.

Php

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Php

PHP

Definition:Definition: PHP stands for Personal Home Page. The PHP

Hypertext Preprocessor allows web developers to create dynamic content that interacts with databases. PHP applications are normally found on Linux servers and in conjunction with MySQL databases. It provides those servers with functionality similar to that provided to the Windows platform by Active Server Pages technology.

Page 2: Php

PHP statements must be inside of PHP tags to be processed by the PHP interpreter. Each PHP statement must end with a semi-colon, which tells the PHP interpreter that the statement is complete. If a semi-colon does not appear at the end of a line, the interpreter will assume that the statement continues onto the next line.

Page 3: Php

The PHP interpreter condenses all sequential whitespace in PHP scripts to a single whitespace. This convenient feature allows PHP developers to structure their code in a readable format without being concerned about the effects of line breaks and tabs.

Page 4: Php

COMMENTSCOMMENTS

PHP has two forms of comments:

* Single-line comments begin with a double slash (//).

* Multi-line comments begin with "/*" and end with "*/".

Page 5: Php

SYNTAXSYNTAX

// This is a single-line comment/*

This is a multi-line comment.*/

Page 6: Php

PHP FUNCTIONPHP FUNCTION

There are literally hundreds of built-in PHP functions that do everything from returning the current date

and time on the server to pulling data out of a database. A function might take zero arguments (e.g, phpinfo(), which returns information on the

PHP environment) or it might take several arguments

Page 7: Php

SYNTAXSYNTAX

The syntax for calling a function is straightforward:

Syntax:

function_name(arguments);function_name(arguments);

Page 8: Php

SAMPLE CODESAMPLE CODE

PhpBasics/Demos/PhpInfo.php<html><html><head><head><title>PHPINFO</title><title>PHPINFO</title></head></head><body><body><?php<?php//Output information on the PHP environment//Output information on the PHP environmentphpinfo();phpinfo();?>?></body></body></html></html>

Page 9: Php

PHP OPERATORPHP OPERATOR

Mathematical Operators Operator Name.

Example: Addition

+ $a + $b

Subtraction -

$a - $b

Page 10: Php

Multiplication

*$a * $b

Division

/

$a / $b

Modulus

%

$a % $b

Page 11: Php

String Operators Operator Name

Example

.Concatenation

$a . $b

'Hello' . ' world!'

Page 12: Php

Assignment Operators Operator Name Example

=

Assignment

$a = 1;

$c = 'Hello' . ' world!';

+=

-=

*=

/=

%=

.=

Page 13: Php

Combination Assignment

$a += 1;

$a -= 1;

$a *= 2;

$a /= 2;

$a %= 2;

$a .= ' world!';

Page 14: Php

Increment By One

++

$a++;

++$a;

Decrement By One

--

$a--;

--$a;

Page 15: Php

Other Operators Operator Name Example

Ternary

?:

$foo = ($age >= 18) ? 'adult' : 'child';

Error Suppression

@

Creating Dynamic Pages

$a = @(1/0);

Page 16: Php

SAMPLE CODE:<html><html><head><head>

<title>Hello World!</title><title>Hello World!</title></head></head><body><body><?php<?php

//Write out Hello World!//Write out Hello World!echo 'Hello World!';echo 'Hello World!';

?>?></body></body></html></html>

PHP.NETPHP.NET

Page 17: Php

BASIC PHP SYNTAXBASIC PHP SYNTAX

PHP Tags: PHP code must be contained in special tags so

that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take

several forms:<?php?php

PHP CODE GOES IN HEREPHP CODE GOES IN HERE?> ?>

Page 18: Php

This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the

document to become poorly formed.

<script language="php"><script language="php">

PHP CODE GOES IN HEREPHP CODE GOES IN HERE

</script> </script>

Page 19: Php

Less is more.  The shortest and easiest way to deal with the xml tag problem assuming short tags is

enabled and you don't care to listen to people who want you to always use the full php tag is this:

<<??>?xml version="1.0" encoding="utf-8"?><<??>?xml version="1.0" encoding="utf-8"?>

Page 20: Php

you also can use this kind of syntax:

<?php if( condition ): ?><?php if( condition ): ?>

    <?php else: ?><?php else: ?>

    <?php endif; ?><?php endif; ?>

Page 21: Php

<?PHP CODE GOES HERE

?>

"Short" tags.

<%PHP CODE GOES HERE

%>

HTML STYLE TAGHTML STYLE TAG