Category: php

Individuare città da indirizzo IP visitatore – XBMC-Italia 0

Individuare città da indirizzo IP visitatore – XBMC-Italia

[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; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)’; $url = ‘http://ipinfodb.com/ip_locator.php?ip=’ . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION => 1, […]

Convertire file da PDF a JPG con ImageMagick – XBMC-Italia 0

Convertire file da PDF a JPG con ImageMagick – XBMC-Italia

[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 JPG con le impostazioni indicate exec(‘convert “’.$pdf_file.’” -colorspace RGB -resize 800 “’.$save_to.’”’, $output, $return_var); if($return_var == 0) { print “Conversione avvenuta […]

Estrarre una parte di testo da una stringa – XBMC-Italia 0

Estrarre una parte di testo da una stringa – XBMC-Italia

[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 that returns the stringa between two stringas. function extractstringa($stringa, $inizio, $fine) { $stringa = ” “.$stringa; $ini = strpos($stringa, $inizio); if […]

Creazione Automatica dei link nel testo – XBMC-Italia 0

Creazione Automatica dei link nel testo – XBMC-Italia

[sourcecode language=”php”] <?php function AutoLinkUrls($str,$popup = FALSE){ if (preg_match_all(“#(^|s|()((http(s?)://)|())(w+[^s)<]+)#i”, $str, $matches)){ $pop = ($popup == TRUE) ? ” target=”_blank” ” : “”; for ($i = 0; $i < count($matches[‘0’]); $i++){ $period = ”; if (preg_match(“|.$|”, $matches[‘6’][$i])){ $period = ‘.’; $matches[‘6’][$i] = substr($matches[‘6’][$i], 0, ‐1); } $str = str_replace($matches[‘0’][$i], $matches[‘1′][$i].'<a href=”http’. $matches[‘4′][$i].’://’. $matches[‘5’][$i]. $matches[‘6′][$i].’”’.$pop.’>http’. $matches[‘4′][$i].’://’. $matches[‘5’][$i]. […]

Ricavare URL della pagina corrente – XBMC-Italia 0

Ricavare URL della pagina corrente – XBMC-Italia

[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”]; } return $pageURL; } echo curPageURL(); ?> [/sourcecode]

Ottenere l’estensione di un file – XBMC-Italia 0

Ottenere l’estensione di un file – XBMC-Italia

[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à – XBMC-Italia 0

Download di File con limite di velocità – XBMC-Italia

[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 */ flush(); /* open file */ $fh = @fopen($download_file, ‘r’); while(!feof($fh)){ /* send only current part of the file to browser […]

Individuare città da indirizzo IP visitatore – XBMC-Italia.it 0

Individuare città da indirizzo IP visitatore – XBMC-Italia.it

[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; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)’; $url = ‘http://ipinfodb.com/ip_locator.php?ip=’ . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION => 1, […]

Ottenere l’estensione di un file – XBMC-Italia.it 0

Ottenere l’estensione di un file – XBMC-Italia.it

[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]

Convertire file da PDF a JPG con ImageMagick – XBMC-Italia.it 0

Convertire file da PDF a JPG con ImageMagick – XBMC-Italia.it

[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 JPG con le impostazioni indicate exec(‘convert “’.$pdf_file.’” -colorspace RGB -resize 800 “’.$save_to.’”’, $output, $return_var); if($return_var == 0) { print “Conversione avvenuta […]

Ricavare URL della pagina corrente – XBMC-Italia.it 0

Ricavare URL della pagina corrente – XBMC-Italia.it

[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”]; } return $pageURL; } echo curPageURL(); ?> [/sourcecode]

Creazione Automatica dei link nel testo – XBMC-Italia.it 0

Creazione Automatica dei link nel testo – XBMC-Italia.it

[sourcecode language=”php”] <?php function AutoLinkUrls($str,$popup = FALSE){ if (preg_match_all(“#(^|s|()((http(s?)://)|())(w+[^s)<]+)#i”, $str, $matches)){ $pop = ($popup == TRUE) ? ” target=”_blank” ” : “”; for ($i = 0; $i < count($matches[‘0’]); $i++){ $period = ”; if (preg_match(“|.$|”, $matches[‘6’][$i])){ $period = ‘.’; $matches[‘6’][$i] = substr($matches[‘6’][$i], 0, ‐1); } $str = str_replace($matches[‘0’][$i], $matches[‘1′][$i].'<a href=”http’. $matches[‘4′][$i].’://’. $matches[‘5’][$i]. $matches[‘6′][$i].’”’.$pop.’>http’. $matches[‘4′][$i].’://’. $matches[‘5’][$i]. […]

Download di File con limite di velocità – XBMC-Italia.it 0

Download di File con limite di velocità – XBMC-Italia.it

[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 */ flush(); /* open file */ $fh = @fopen($download_file, ‘r’); while(!feof($fh)){ /* send only current part of the file to browser […]

Estrarre una parte di testo da una stringa – XBMC-Italia.it 0

Estrarre una parte di testo da una stringa – XBMC-Italia.it

[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 that returns the stringa between two stringas. function extractstringa($stringa, $inizio, $fine) { $stringa = ” “.$stringa; $ini = strpos($stringa, $inizio); if […]