php (1)
php (1)
PHP
Php
Php is powerful server side programming language.
Php originally stands for personal home page but know its stands for hypertext pre processor
Php files are executed on servers like apache
http(hyper text transfer protocol ):is a protocol used over a website between client and server
The web browser is a client and the web server is the server .the client request a page and the server the
request.
Major examples webserver
1 apache: the second most popular web server software (31% of known websites use it )
2 NGINX:is the most popular web server(33% of known websites use it )
http uses port 80 by default, while https uses port 443.
Cont’d
Php syntax::
Php scripts can be placed anywhere in the document but the must start and end
with <? Php and ?> respectively.
Php files can contain HTML,CSS AND JAVASCRIPT codes , php files can also
contain only php code.
echo: is a php keyword used to display a text.
Php variables: used to store a value that can be used throughout a script.]
variables are declared using the $ sign followed by identifier
Variable name (identifiers): variables are declared using the $ sign followed by
identifier. Identifier can contain letter number and underscore but must start with a
letter or underscore
Rules of a variable name:
1 must start with $ sign
2 variable names are case sensitive
3 the first letter after $ must be a letter or underscore(_)
4 there are no restriction on the length of a name.
Php constants : constants are values that cannot be changed once they are
defined.they are used to store values that should remain the same throught the
execution of the code.
There are 2 ways to declare constants
1 by using the const key word
2 by using define() function
BASICS OF PHP
Comments: comments has no impact on the code or program none what so ever.
Single line comment:
// comments a nd #comments
Multiple line comment:
/*comments */
Variable names(identifiers): can be letters numbers and underscore but must start with
letter or underscore(_)
are unique name given to a variable
Rules of identifiers:
1 must start with the dollar sign ($)
2 php variables are case sensetives (capital and small letter are different )
3 variable name cant start with number .it can start with letter or underscore
4 the length of variable name is not restricted.
Php datatypes
1 write a php code that display your full name, age and section. NB: each of them
has to be displayed in separate line
2 write a php code that display the sum, subtraction ,division and multiplication of
10 and 5
3 write a php code that display 5 of your favorite colors by using array.
4 Write php code that display list of numbers from 100 to 10 downwards