Nel tutorial di oggi imparerete come creare una funzione PHP che prende in ingresso il codice di risposta HTTP e ne restituisce la descrizione.
function getStatusCodeMessage($status){ // these could be stored in a .ini file and loaded // via parse_ini_file()... however, this will suffice // for an example $codes = Array( 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => …
…
…
…
In questo semplice tutorial PHP vi mostreremo come creare una funzione che rileva se l’utente che sta visitando il vostro sito sta utilizzando un dispositivo Android.
function isItAndroid() { $ua = strtolower($_SERVER['HTTP_USER_AGENT']); if(stripos($ua,'android') !== false) return true; else return false; } …
Nel tutorial PHP di oggi vi mostreremo come creare una funzione che crea automaticamente un link se trova all’interno di un testo una username Twitter.
function twtreplace($content) { $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",$content); return $twtreplace; }
Se volete applicare questa funzione su un blog WordPress, incollate il seguente codice all’interno del file functions.php del vostro tema WordPress.
function twtreplace($content) { $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",…
…
…