PHP Tutorials For Beginners:
HTML knowledge is required prior to this
PHP is a hypertext preprocessor, i.e PHP is a language for development of HTML documents are interpreted on the server when required.
Unlike a PHP programming language need not be compiled before running it at the time that invokes the Web server will interpret the PHP code is embedded in the document, so a website programmed PHP scripts has more functionality than those that are uniquely designed using standard HTML.
Another substantial difference is that the code PHP is processed by the server, not the client gets the result of that processing.
The syntax of PHP is identified to be embedded between opening and closing tags code blocks. Each line of PHP code should end with the sign semicolon; . To indicate a variable $ sign is used before a text string. .
These three features will be more specific later in this tutorial form a first example of a simple document in PHP is:
<html> <head>
<title> My first PHP script </ title>
</ head>
<body> <? php echo “Hello world.”; ?> </ body>
</ html>
When viewing this document in a browser and being served by a web server should see a page with only the text Hello World.
Initial Considerations
Getting Started this manual and you’ll have access to a web server with PHP installed, or possibly have configured on your computer a web server and PHP. To configure your computer the most recommended web server is Apache which you can find in google to install complete package. Note: To use this manual is advisable to have some knowledge of HTML syntax and how to publish files in a webserver
Learn configuration
For parameters that has been compiled PHP preprocessor you are using, and the parameters and variables Web server can use the phpinfo () in a script like this:
< html>
<head> </ head>
<body> <? php phpinfo ();?> </ body>
</ html>
Ways to use PHP with HTML
There are at least three different ways to use PHP in combination with HTML tags
The first option, which we have seen, is to combine the instructions PHP within the HTML code Observe how in the examples above, it is an HTML document with PHP code embedded for preprocessing.
Another option is to generate all the HTML code through instructions PHP:
<?php echo "<html>"; echo " <head>"; echo " </head>"; echo " <body>"; echo "Hello World"; echo " </body>"; echo " </html>"; ?>
Could also combine PHP code to get different behaviors of some pages according to certain parameters:
<html> <head> </ head> <body> <? php if ($ user_authorized) { ?>
Displays information for authorized users
<? php } else { ?>
Information for unauthorized users
<? php } ?> </ body> </ html>
In the example above look like an if statement is left open to make way for HTML tags and then another PHP section opens to the else statement also subsequently closed in a third PHP code.
Tags for opening and closing PHP code As you may have noticed the <? php and?> tell the server that the code between them should be interpreted as PHP code and therefore preprocessed to generate the web document. . However there are other tags that allow you to embed PHP code in an HTML document
First option: Tags PHP
<? php echo "This is the first choice for PHP code tags"; ?>
Second option: Short tags
<? echo "is used for a single line of command"; ?>
Option Three: Short tags + ‘=’
? <= expression> // is an abbreviation of the previous, // where the sign is written = the judgment removes echo To use short tags, the directive must be enabled short_tags in the configuration file php.ini
fourth option: ASP tags
<% echo “This is an example of ASP tags”; %> To use the tags of ASP, the asp_tags directive must be enabled in the php.ini configuration file
Fifth option: Syntax script
<script language = “php”> echo “Also in this way you can write programs in PHP”; </ script>
PHP scripts First Comment PHP code
<? php // This is an example for comment a line # and this is another example of comment / *
The comment can extend over a line with the diagonal and the asterisk * / ?>
Show information Echo Displays a string Example:
<? php echo "This is a string"; echo "But can also be deployed." $ N. "Concatenated strings"; ?> print (string)
Displays a string
<? php print "Displays the text string"; print "Even if the chain is on more than one line "; ?>
Arithmetic
<? php $ a = 1; $ b = 2, c = 3 $, $ d = 4; #Suma $ res = $ a + $ b + $ c + $ d; print ("a + b + c + d =" $ res.) ; $ res = $ c + $ a; print ("c - a =" $ res.); # Multiplication $ res = $ b * $ d; print ("b * c =" $ res.) # Division $ res = $ d / $ b; print ("d / b =" $ res.); ?>
. There are also functions postincrement and preincrement increases in unit variable
<? php #Example preincrement and postincrement $ a = 1;print $ a; # Prints 1 print ++ $ a # Prints 2 print $ a ++ # Prints 2 print $ a # Print 3 ?>
Basic Control Structures
The basic control structures are useful to tell a program how to behave according to certain parameters or variables that occur in the program, for example if we want to make a program or different function whether a variable is a positive or negative number, or would like to repeat a statement a number of times, etc.
If … else …
Give two possible options to continue in the program according to the value of a variable
<? php $ a = 5; if ($ a <10) { echo "a is less than ten"; } else { echo "a is greater than or equal to ten"; } ?> switch
This control structure will indicate to the program commands to be followed by the value of the variable evaluated.
<? php $ letter = "a"; switch ($ letter) { case = "a": echo "The value is";break; case = "b" : echo "The value is b"; break; case = "c": echo "The value is c"; break; default: echo "The value is not a nor b nor c" } >?
while The while loop whose translation literal is “while” allows you to run a series of commands cyclically while a certain condition is met. For example if we wanted to display the numbers 1 to 100:
<? php while ($ a <= 100) { echo $ a. "<br />"; $ a = $ a + 1; } ?> for
A for statement is used to perform a series of commands or statements a specific number of repetitions.
<? php for ($ a = 1; $ a <= 20; $ a ++) { echo "This is step". $ A; } ?> << Previous - Next >>
2 thoughts on “PHP Tutorials For Beginner”
Thank you for this information, I appreciate your effort, please keep us update.
Thank you for this information.