PHP
(a quick example)
A function that is passed into another function.
The function then gets called inside the other function.
A callback function can change the way a function acts.
function fetch ($url, $after) { FETCH CONTENT FROM URL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_ RETURNTRANSFER, true); $result = curl_exec($ch); CALLBACK AFTER FETCH if (is_callable($after)) { $after($result); } }
CALLBACK - SAVE TO FILE function save ($data) { file_put_contents("demo.html", data); }
CALLBACK - DIRECT OUTPUT function show ($data) { echo $data; }
FETCH CONTENT & SAVE TO FILE fetch("http://site.com", "save");
FETCH CONTENT & OUTPUT IT fetch("http://site.com", "show");