Php: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
<slidy theme="aa" />
<slidy theme="aa" />


====PHP====
==PHP==
* Server side programming language
* Server side programming language
* LAMP model
* LAMP model
Line 7: Line 7:




====Hello World====
==Hello World==
<source lang="php">
<source lang="php">
<!DOCTYPE html>
<!DOCTYPE html>
Line 18: Line 18:




====pros====
==pros==
* frameworks
* frameworks


====cons====
==cons==




Line 38: Line 38:




==== Mixing with HTML====
== Mixing with HTML==
<source lang="php">
<source lang="php">
<?php  
<?php  
Line 51: Line 51:
</source>
</source>


==== Syntax ====
== Syntax ==
<source lang="php">
<source lang="php">
function myFunction() { //declares a function, this is named myFunction
function myFunction() { //declares a function, this is named myFunction
Line 62: Line 62:
</source>
</source>


==== Weirdness of PHP ====
== Weirdness of PHP ==
<source lang="php">
<source lang="php">
<?php
<?php

Revision as of 22:57, 21 April 2013

<slidy theme="aa" />

PHP

  • Server side programming language
  • LAMP model

LAMP.png


Hello World

<!DOCTYPE html>
<meta charset=utf-8>
<title>PHP Test</title>
<?php
 echo 'Hello World';
?>


pros

  • frameworks

cons

  • php.net



  • error logs /cat /var/log/apache2/error.log / run file
  • Every block of PHP code must start with <?php and end with ?>.
  • You need to place a semi-colon (;) at the end of each line of PHP code.
  • variable names must start with a dollar sign ($).



Mixing with HTML

<?php 
 // this is a PHP comment
$myHeader = "Header made with echo";
echo "<h3>".$myHeader."</h3>";
?>

<!--  Is similar to (note HTML comment)  -->
<?php $myHeader2 = "Header made with with HTML"; ?>
<h3> <?php echo $myHeader2; ?> </h3>

Syntax

function myFunction() { //declares a function, this is named myFunction
 return 'John Doe'; //returns the value 'John Doe'
}

echo 'My name is ' . myFunction() . '!'; //outputs the text concatenated with the return value of myFunction.
 //myFunction is called as a result of this syntax.
//The result of the output will be 'My name is John Doe!'

Weirdness of PHP

<?php
if("foo" == TRUE){
	echo 'YES! foo == TRUE, but we didnt define it yet? Well okay....</br></br>';
}

if("foo" == 0){
	echo 'Huh? "foo" is also a number?</br></br>';
}

if(TRUE == 0){
	echo 'therefor True is also 0, right?! ';
}else{
	echo "WRONG!";
}

?>