Categoria: PHP

PHP

Individuare città da indirizzo IP visitatore 0

Individuare città da indirizzo IP visitatore

[sourcecode language=”php”] <?php function detect_city($ip) { $default = ‘UNKNOWN’; if (!is_string($ip) || strlen($ip) < 1 || $ip == ‘127.0.0.1’ || $ip == ‘localhost’) $ip = ‘8.8.8.8’; $curlopt_useragent = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1;...

Convertire file da PDF a JPG con ImageMagick 0

Convertire file da PDF a JPG con ImageMagick

[sourcecode language=”php”] <?php $pdf_file = ‘demo.pdf’; $save_to = ‘demo.jpg’; // assicurarsi che il server abbia i permessi di scrittura nella cartella // esegue il comando ‘convert’ di ImageMagick e trasforma il PDF in una...

Estrarre una parte di testo da una stringa 0

Estrarre una parte di testo da una stringa

[sourcecode language=”php”] <?php // stringa dalla quale effettuare l’estrazione $stringa = ‘Questa è la stringaa dalla quale <pre>estrarre il contenuto</pre> compreso tra due tag.’; // Call the function. echo extractstringa($stringa, ‘<pre>’, ‘</pre>’); // Function...

Creazione Automatica dei link nel testo 0

Creazione Automatica dei link nel testo

[sourcecode language=”php”] <?php function AutoLinkUrls($str,$popup = FALSE){ if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)){ $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; for ($i = 0; $i < count($matches[‘0’]); $i++){ $period = ”; if...

Ricavare URL della pagina corrente 0

Ricavare URL della pagina corrente

[sourcecode language=”php”] <?php function curPageURL() { $pageURL = ‘http’; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; }...

Ottenere l’estensione di un file 0

Ottenere l’estensione di un file

[sourcecode language=”php”] <?php function ottieni_estensione_file($nome_file) { /* may contain multiple dots */ $parti_stringa = explode(‘.’, $nome_file); $estensione = $parti_stringa[count($parti_stringa) ‐ 1]; $estensione = strtolower($estensione); return $estensione; } ?> [/sourcecode]

Download di File con limite di velocità 0

Download di File con limite di velocità

[sourcecode language=”php”] <?php $velocita_download = 10.20; $download_file = ‘download‐file.zip’; $file_destinazione = ‘target‐file.zip’; if(file_exists($download_file)){ /* headers */ header(‘Last‐Modified: ‘.gmdate(‘D, d M Y H:i:s’).’ GMT’); header(‘Cache‐control: private’); header(‘Content‐Type: application/octet‐stream’); header(‘Content‐Length: ‘.filesize($download_file)); header(‘Content‐Disposition: filename=’.$file_destinazione); /* flush content...