1.Basic PHP

1. Active Web Sites
-allow the user to be sent customized pages and which offer a more dynamic browsing experience. 
-built with a combination of languages and technologies, and we can use any one of them alone, or any number together.
-independent (in the sense that we don't have to learn one technology before we can learn another).

2. Active Web Sites - technologies

client-side technologies 
-ActiveX Controls – created by Visual C++ or Visual Basic
-Java Applets
-Client-side Script and Dynamic HTML

Server-side technologies
-CGI
-Proprietary web-server APIs such as ISAPI and NSAPI
-Active Server Pages
-JavaServer Pages and Java Servlets
-Server-Side JavaScript
-PHP

3. Server Side Scripting - Benefits
-Minimizes network traffic by limiting the need for the browser and server sending information back and forth to each other.
-Makes for quicker loading time since, in the end, we're only actually downloading a page of HTML.
-Avoids browser-compatibility problems.
-Can provide the client with data that does not reside at the client.
-Provides improved security measures.


4. How PHP Works?
-The server reads the PHP and processes it according to its scripted directions. 
-PHP creates an HTML page on the fly based on parameters. 
-The client receives  the HTML file from PHP server and displays it using a web browser.


5. Basic PHP Syntax - PHP Tags
<?php  ?>
Standard - compatible with all server settings
<?     ?>
Short tags – easier but may conflict with xml and may not be supported in all server settings
<%     %>
ASP tags – same tags with asp, not supported in all server settings
<script language=“php”> </script>
Script tags - compatible with all server settings

6. Basic PHP Syntax – White Spaces
-They don’t matter
-You can have a code which may be separated by n number of new lines
-You can also have a PHP code that is only one line

7. Basic PHP Syntax - Comments
// - comments only one line of code
# - comments only one line of code
/**/ - comments more than one line of code

8. Basic PHP Syntax - Print functions
print() – returns an integer 1 all the time
 <?php 
 print "hello world"; 
 ?> 
echo() – accepts multiple parameters
<?php 
 echo "hello world“; 
 ?>

9. Variables 
a holder for a type of data. 
-numbers,
-strings of characters, 
-objects, 
-arrays,
-booleans. 
Loosely typed
-Takes the type of the value that is assigned to it



10. Variables - Types
Standard
-Integer
-Double
-String
-Boolean
-Object
-Array
Special
-Resource
-NULL


11. Variables - Naming
Should start with $
Alphanumeric
can contain ‘_’
Cannot contain space
  $user = "juan"; 
  print "hello, $user"; // hello, juan 


12. Variables – Automatic Type Conversion
Consider the script
$a =1;
$b=2.2;
$c= $a + $b;
echo $c;  //result: 3.2


13. Variables – Manual Type Conversion
Type casting
$a =1;
$b=2.2;
$c= $a + (int)$b;
echo $c;  //result:  3


14. Variables – Manual Type Conversion
Possible Type Cast
-(int)
-(integer)
-(real)
-(double)
-(float)
-(string)
-(array)
-(object)


15. Variables – Type Testing using functions
is_array() Returns true if the argument is an array
is_bool() Returns true if the argument is boolean
is_double() Returns true if the argument is a double
is_int() Returns true if the argument is an integer
is_object() Returns true if the argument is an object
is_string() Returns true if the argument is a string
is_null() Returns true if the argument is null
is_resource() Returns true if the argument is a resource


16. Variables - Constants
define (“CONSTANT_NAME”,42);
By convention, the name of the constant should be in uppercase letters. 
Accessed with the constant name only; no dollar symbol is required. 
Example:
<?php 
define ("USER", "Gerald"); 
print "Welcome".USER; 
?>


17. Single Quotes vs. Double Quotes 
Double quotation marks allow the parsing of variables 
 $user = “juan”;
 print “hello, $user” //result:  hello, juan
string to be output exactly as you typed it 
 print ‘hello, $user’ //result:  hello, $user


18. Operators - Assignment
= takes the value of its right operand and assigns it to its left operand 
Example
$address = “cebu"; 
print ( $address = “cebu" ); 
//result:  cebu


19. Operators - Arithmetic
+
-
/
*
%


20. Operators - Concatenation
Treating both operands as a string
Appends right operand to the left
Example
$feet = 20; 
print "the width is ".($feet*12)." inches";
//result:       the width is 240 inches 


21. Operators - Comparison
==
!=
===
Identical
Left is equivalent to right and they are the same type
>
>=
<
<=


22. Operators - Logical
||
or
&&
and
!
xor

2 comments: