Heey,
Zou iemand mij function uit kunnen leggen met de nut of een linkje ofso?
m.v.g. Wouter
Zou iemand mij function uit kunnen leggen met de nut of een linkje ofso?
m.v.g. Wouter
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] tekst[COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700]) {[/COLOR]
[COLOR= #0000BB]$new[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Hoi[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$new[/COLOR][COLOR= #007700];[/COLOR]
?> [COLOR= #0000BB]<?php[/COLOR] tekst[COLOR= #007700]([/COLOR][COLOR= #DD0000]Tot ziens![/COLOR][COLOR= #007700]);[/COLOR]?> HoiTot ziens! function datum($var){
$dat = date($var);
return $dat;
}
echo is weergeven op het scherm, en return is een waarde terugsturen vanuit de functie.[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] voorbeeld[COLOR= #007700]() {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Voorbeeld[/COLOR][COLOR= #007700];
}[/COLOR]
voorbeeld[COLOR= #007700]();[/COLOR]
?> [COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] voorbeeld[COLOR= #007700]() {[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #DD0000]Voorbeeld[/COLOR][COLOR= #007700];
}[/COLOR]
[COLOR= #0000BB]$variabel[/COLOR] [COLOR= #007700]=[/COLOR] voorbeeld[COLOR= #007700]();[/COLOR]
?> Rik schreef:Voor een layout functie mag dat toch wel ? Want die echo je toch altijd ?En ik raad je aan om altijd return te gebruiken (buiten errorclasses, maar die zijn momenteel toch te hoog gegrepen). Door een return te gebruiken heb je meer controle over wat er gebeurd. Bovendien kan je dankzij een return je functie ook in andere functies aanroepen, en de teruggegeven waarde verder gaan manipuleren. Bij het echoën kan dat niet.
Een functie is vooral voor readability erg handig. Als je in je project een code hebt van 20 regels die je wel 3x in je document gebruikt, dan kan je dat net zo goed in een functie zetten, en die functie 3x aanroepen. Dat staat veel netter en is veel overzichtelijker.
Maartenl schreef:Buiten het feit dat jullie gewoon rechtstreeks HTML in een functie pleuren en dat dan een layout functie noemen, raad ik je toch aan om danEen functie is vooral voor readability erg handig. Als je in je project een code hebt van 20 regels die je wel 3x in je document gebruikt, dan kan je dat net zo goed in een functie zetten, en die functie 3x aanroepen. Dat staat veel netter en is veel overzichtelijker.Eerdere citaten tonen
Rik schreef:En ik raad je aan om altijd return te gebruiken (buiten errorclasses, maar die zijn momenteel toch te hoog gegrepen). Door een return te gebruiken heb je meer controle over wat er gebeurd. Bovendien kan je dankzij een return je functie ook in andere functies aanroepen, en de teruggegeven waarde verder gaan manipuleren. Bij het echoën kan dat niet.
Voor een layout functie mag dat toch wel ? Want die echo je toch altijd ?
echo $layout->boven(); $layout->boven(); [COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] MijnFunctieNaam[COLOR= #007700]([/COLOR][COLOR= #0000BB]$parameter1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$parameter2[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$parameter1[/COLOR][COLOR= #007700]) &&[/COLOR] [URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$parameter2[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$parameter1[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] en [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$parameter2[/COLOR][COLOR= #007700]);
}
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] MijnFunctieNaam[COLOR= #007700]([/COLOR][COLOR= #DD0000]appel[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]peer[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// Dit geeft "Appel en Peer" terug.[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] MijnFunctieNaam[COLOR= #007700]([/COLOR][COLOR= #DD0000]rik[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]luuk[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// Dit geeft "Rik en Luuk" terug.[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] MijnFunctieNaam[COLOR= #007700]([/COLOR][COLOR= #DD0000]html[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]php[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// Dit geeft "Html en Php" terug.[/COLOR]
?> [COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]appel[/COLOR][COLOR= #007700]) &&[/COLOR] [URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]peer[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]appel[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] en [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]peer[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]rik[/COLOR][COLOR= #007700]) &&[/COLOR] [URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]luuk[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]rik[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] en [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]luuk[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]html[/COLOR][COLOR= #007700]) &&[/COLOR] [URL="http://www.php.net/ctype_alpha"]ctype_alpha[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]php[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]html[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] en [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]php[/COLOR][COLOR= #007700]);
}[/COLOR]
?> function safe($query)
$safe = mysql_real_escape_string(htmlentities($query));
retrun $safe; safe(mysql_query("query") function escape($string){
return mysql_real_escape_string($string);
}