Categoria: Frammenti di Codice

Frammenti di Codice

Ottenere il proprio numero di Telefono 0

Ottenere il proprio numero di Telefono

Frammenti di codice Android – Ottenere il proprio numero di Telefono [sourcecode language=”C”] private String getMyPhoneNumber(){ TelephonyManager mTelephonyMgr; mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return mTelephonyMgr.getLine1Number(); } private String getMy10DigitPhoneNumber(){ String s = getMyPhoneNumber(); return s.substring(2); }...

Formattare una data 0

Formattare una data

[sourcecode language=”javascript”] <script type="text/javascript"> <!– function DateFmt() { this.dateMarkers = { d:[‘getDate’,function(v) { return ("0"+v).substr(-2,2)}], m:[‘getMonth’,function(v) { return ("0"+v).substr(-2,2)}], n:[‘getMonth’,function(v) { var mthNames = ["Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic"]; return mthNames[v]; }], w:[‘getDay’,function(v) { var dayNames = ["Dom","Lun","Mar","Mer","Gio","Ven","Sab"];...

Inserire sfondo in casella di testo 0

Inserire sfondo in casella di testo

[sourcecode language=”html”] <html> <head> <style type="text/css"> .searchBox{ background-image:url(‘lenteingrndimento.gif’); background-repeat:no-repeat; padding-left:20px; } </style> </head> <body> <input type="text" name="search" class="searchBox"> </body> </html> [/sourcecode]

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]