Senza usare un riga di codice dinamico ecco un bottone java per condivedere tutte le pagine del proprio sito sul social network Digg.
N.b: i ... equivalgono a < >
...script type="text/javascript...
digg_url = 'WEBSITE_URL'; #########questo va tolto##############
digg_bgcolor = '#ff9900';
digg_skin = 'compact';
digg_window = 'new';
.../script...
...script src="http://digg.com/tools/diggthis.js" type="text/javascript"... .../script...
il risultato di seguito:
Partendo dal concetto che la condivisione sarà il punto fondamentale per l'indicizzazione dei propri siti web.
Non dimentichiamoci di creare un account su Digg.
Una serie di codici sperimentati, e quindi funzionanti, di php e css per l'ottimizzazione dei siti web sui motori di ricerca.
Convertire caratteri speciali, php
Come togliere i caratteri speciali e spesso e volentieri invisibili che disturbano il nostro codice:
$pippo= str_replace("\n","", $pippo);
$pippo = str_replace("\r","", $pippo);
$pippo = str_replace("\t","", $pippo);
Codice che risolverà il dannoso problemi degli spazi invisibili
$pippo= str_replace("\n","", $pippo);
$pippo = str_replace("\r","", $pippo);
$pippo = str_replace("\t","", $pippo);
Codice che risolverà il dannoso problemi degli spazi invisibili
Visualizzare file esterni con safe_mode abilitato, script php
Capita più spesso che i server in cui girano i nostri siti siano protetti dalla modalità safe_mode abilitata. A capita sempre più spesso che ci sia utile l'accesso a file esterni, come file xml. Di seguito un utile script che visualizza sul nostro sito la pagina di www.php.net
#usage:
$r = new HTTPRequest('http://www.php.net');
echo $r->DownloadToString();
class HTTPRequest
{
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "\r\n";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
?>
Da provare, senza abusare
#usage:
$r = new HTTPRequest('http://www.php.net');
echo $r->DownloadToString();
class HTTPRequest
{
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "\r\n";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
?>
Da provare, senza abusare
Number_format per l'euro €
Il comando number_format nasce per il dollaro e/o sterlina, quindi per l'euro, in visualizzazione, possiamo avere dei problemi. Vediamo come risolverli:
Abbiamo il nostri prezzi:
$prezzo1="550.50";
###il . è fondamentale per la somma,senza . non si somma con il prezzo2###
$prezzo2="550.30";
con una semplice somma avremo:
$totale=$prezzo1+$prezzo2;
e avremo in visualizzazione: 1100.80
risultato che non è corretto per l'euro, si richiede la , per i decimali e il .
ecco number_format che ci aiuta:
$totale=number_format($totale, 2, ',', ' '); ##visualizza 2 decimali divisi da , e le migliaia divisi da spazio###
$totale=str_replace(" ",".",$totale); ###trasformo lo spazio in .####
quindi in visualizzazione avrò: 1.100,80
N.B: il valore creato è solo un valore di visualizzazione, per sommarlo dovremo sempre lavorare con il totale creato senza number_format
Abbiamo il nostri prezzi:
$prezzo1="550.50";
###il . è fondamentale per la somma,senza . non si somma con il prezzo2###
$prezzo2="550.30";
con una semplice somma avremo:
$totale=$prezzo1+$prezzo2;
e avremo in visualizzazione: 1100.80
risultato che non è corretto per l'euro, si richiede la , per i decimali e il .
ecco number_format che ci aiuta:
$totale=number_format($totale, 2, ',', ' '); ##visualizza 2 decimali divisi da , e le migliaia divisi da spazio###
$totale=str_replace(" ",".",$totale); ###trasformo lo spazio in .####
quindi in visualizzazione avrò: 1.100,80
N.B: il valore creato è solo un valore di visualizzazione, per sommarlo dovremo sempre lavorare con il totale creato senza number_format
Iscriviti a:
Post (Atom)