Segui le novità: su Telegram
17.02.2014

Basic Php in few words for my english speaking, not developers, remote co workers ... :-)

Just how to begin developing in php

Php is very easy.

you create a text file, with extension .php

In it you can write html or code. Example:

<html>
<body>
<?php echo "hello world"; ?>
</Body>
</html>

A good practice is to output the text all togheter at the end, so:

<?php
#this is a comment
$hello="hello world";
$bdy=<<<BDY
<html>
<body>
$hello
</Body>
</html>
BDY;
echo $bdy;
?>

every command must end with ;

 


##examples of if:

if (1==1) {echo "equals";} else {echo "different";}
if (1!=0) {echo "equals";} else {echo "different";}
if (!is_numeric($pagenumber)) {
        echo "error";
} else {
        echo "is a number, ok !";
}

 

Numbers
$counter=$counter+1;
is the same of:
$counter++;

 

 


Include
A very useful command is: include, include_once, require, require_once
to include an external file with some commons constants, functions, and
so on.

 


Functions:
function sum($a,$b) {
return $a+$b
}

Instead to add a string to another:

function addstring($a,$b) {
return $a.$b
}

 


Passing datas

How to take data from url, ex https://pippo.com/index.php?Url=myurl

echo $_GET["Url"];

From a form:

echo $_POST["Url"];

From an url or a form:

echo $_REQUEST["Url"];

Never, never think at datas coming from the web as something you can use
without checking them. It's a security issue.


Just to start :)


You can find many simple routines on tizag.com , the great online php
manual, and others on phpclasses.

To begin install locally apache, php, mysql, phpmyadmin on ubuntu (mamp
on mac, wampserver on win), find the root of the local websites, and
create an index.php file, it is usually the first file read on a directory.


Segui le novità: su Telegram oppure segui il Podcast

Approfondimenti:

Condividi su Facebook







Dal 2004 accompagniamo i clienti nelle tecnologie e nel diritto


menu
Memo