Archives for posts with tag: snippet

Una funzione php comoda per scoprire se un URL esiste (che poi in realtà con php 5 dovrebbe essere sufficiente la cara e vecchia file_exists()):

function url_exists($url) {
    if(!strstr($url, "http://")) {
		$url = "http://".$url;
	}
    $resURL = curl_init();
    curl_setopt($resURL, CURLOPT_URL, $url);
    curl_setopt($resURL, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($resURL, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback');
    curl_setopt($resURL, CURLOPT_FAILONERROR, 1);
    curl_exec ($resURL);
    $intReturnCode = curl_getinfo($resURL, CURLINFO_HTTP_CODE);
    curl_close ($resURL);
    if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) {
       return false;
    } else {
		return true ;
    }
} 

Archiviato in: , , ,

Due snippet veloci:

- JQuery: come controllare se un oggetto esiste?

if ($('#oggetto').length > 0) { ... }

- JQuery: come controllare se un oggetto è visibile?

if ($('#oggetto').is(':visible')) { ... }

Archiviato in: , , ,

Search engine optimization by SEO Design Solutions