Script

Filter
2004-10-07

Redirect

Php
Flytta automatiskt till en annan sida
header("Location: http://www.example.com/"); 
2004-10-06

Hash

Javascript
Associativ array med nycklar och värden
a['ett'] = 'Nummer ett';
a['två'] = 'Nummer två';
for (var key in a) {
    document.write(key + ' = ' + a[key] + '<br>');
} 
2004-10-05

Buffra webbsidan

Php
För att t ex kunna skicka cookies efter http-headern...
ob_start()
Enable output buffering. Output buffering supports multiple levels -- i.e., you can call ob_start() several times.

ob_end_flush()
Send the output buffer, and disable output buffering.

ob_end_clean()
Clean the output buffer without sending it, and disable output buffering.

ob_get_contents()
Return the current output buffer as a string. This allows you to process whatever output the script emitted, if you need to.
 
In addition, you can enable the php.ini directive output_buffering. If you do,
every PHP script will behave as if it begins with a call to ob_start().
2004-10-05

For in loop

Javascript
Tar alla element i en array...
// loopen ignorerar element som inte finns (om det skulle finnas några sådana, dvs undefined)

nameArr = new Array("Rolf", "Sixten", , "Roland");
for (i in nameArr) {
    document.write(i + " = " + nameArr[i] + "<br>");
} 
2004-10-02

Variabla funktionsnamn

Php
Samma funktionsanrop kan kalla på olika funktioner
<?php 
function say_hi() { 
    print("Hi!<br>"); 
}
function say_greeting() { 
    print("How are you today?<br>"); 
}
function say_bye() { 
    print("Have a nice day.<br>"); 
}

$my_func = 'say_hi';
// NOTE: $my_func is a variable and not a function!
// So this is the say_hi() function executing,
// as $my_func contains the string 'say_hi'...
$my_func(); 

$my_func = 'say_greeting'; 
// $my_func now contains the string 'say_greeting',
// so the say_greeting() function will execute...
$my_func(); 

$my_func = 'say_bye';
// som ovan...
$my_func(); 
?> 
🙂