welkom op mijn Php tut.
inleiding
1 .) echo
2 .) variable
3 .) get
4 .) post
5 .) array
1.) waarom werkt niet?
Dat komt omdat er een echo ; tussen moet.
hoe dat werkt?
heel makkelijk!
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Hier de tekst[/COLOR][COLOR= #007700];[/COLOR]
?> en wat is hier het verschil dan?
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"hoi"[/COLOR][COLOR= #007700];[/COLOR]
?> Nu nog niks maar als je bijvoorbeeld een div in een echo wil zitten kan je niet 2 x ""
voorbeeld
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div id="voorbeeld">div</div>[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Kan wel[/COLOR]
?> en
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<div id="[/COLOR]voorbeeld[COLOR= #DD0000]">div</div>"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Kan Niet[/COLOR]
?> dat is dus omdat je geen 2 dubbele " kan hebben
2.) $Variable = hoi; en ik zie geen hoi?
Jha dat klopt
een variable is namelijk een stukje script die zegt "Dit betekent dit"
dus
[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
?> en zegt dus nog niks.
daarvoor gebruiken we de echo functie.
[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// output = dat[/COLOR]
?> bij het ophalen van alleen een variable hoef je geen "" of te gebruiken maar wel een ;
LET OP!
dit kan wel
[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR]
?> Dit kan niet
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
?> dat komt omdat $dit dan nog niet bestaat
3.) de get
Get betekent eigelijk gewoon krijgen.
de functie van de get is om iets uit de url te krijgen.
de url is de link van een website
voorbeeld
www.site.nl/index.php?get=welkom
wij wullen nu uit de get welkom krijgen.
dat doen we met de echo uit stap 1.
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
?> of wat ook kan
[COLOR= #0000BB]<?php
$get[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$get[/COLOR][COLOR= #007700];[/COLOR]
?> nu zou bij de url
Quote:
www.site.nl/index.php?get=welkom
welkom op de pagina staan.
maar als je dit in de url hebt
Quote:
www.site.nl/index.php?get=welbr />kom
zou dit in de pagina staan
Quote:
wel
kom
dat willen we niet.
dus daarvoor gebruiken we htmlentities
die zetten we als het waren om de get heen.
dus bijvoorbeeld.
[COLOR= #0000BB]<?php
$get[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$get[/COLOR][COLOR= #007700]);[/COLOR]
?> nu zou bij
Quote:
www.site.nl/index.php?get=welbr />kom
de output
Quote:
welbr />kom
zijn !
4.) posten! (welkom maar wie ben jij?)
daar gaan we deze functies voor gebruiken.
echo
isset
if
else
$_POST
we beginnen met een Simpele form
<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" value="Verzenden">
</form> nu gaan we eerst kijken of er al iets verzonden is.
dat doen we met de functie isset,post & if
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR]
?>
<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" value="Verzenden">
</form> Maar als de post is verzonden hoe zorg ik ervoor dat die post balk dan weg is?
daar gebruken we else voor
dat ziet er zo uit
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) { <[/COLOR] beginnen met een [COLOR= #007700]{ ----[/COLOR]
[COLOR= #FF8000]// wat als er iets verzonden is?[/COLOR]
[COLOR= #007700]}[/COLOR] [COLOR= #FF8000]// << afsluiten met een }[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[COLOR= #FF8000]// wat als er niets verzonden is?[/COLOR]
[COLOR= #007700]}[/COLOR]
?> dus
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
?>
<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" name="verzenden" value="Verzenden">
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?> 5 .) alles op een reitje
een array is een simpel lijstje die je maakt op dingen een waarde tegeven
bijvoorbeeld.
1 = admin
2 = moderator
3 = lid
4 = verbannen
Dit gaan we nu maken.
[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #FF8000]// we beginnen met een variable om een waarde tegeven aan 1,2,3,4[/COLOR]
?> Nu gaan we de array starten en stoppen
[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700](
);[/COLOR]
?> zoals je ziet staat er nu dat array niks waard is omdat er Niks instaat dat gaan we nu doen.
[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
[COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR]
[COLOR= #007700]);[/COLOR]
?> Nu moeten alle getallen een waarde
dat doen we zo
[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
[COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]moderator[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]lid[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]verbannen[/COLOR]
[COLOR= #007700]);[/COLOR]
?> Nu hebben alle getallen een waarde en zijn ze klaar voor gebruik.
[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
[COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]moderator[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]lid[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]verbannen[/COLOR]
[COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]1[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]2[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]3[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]4[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
?> Later Nog meeer
// eind php tut
?>
zal zo meteen een array tut toevoegen

