The perfect PHP clean url generator

via: http://cubiq.org/the-perfect-php-clean-url-generator/12

In my hunt for the perfect clean url (smart url, slug, permalink, whatever) generator I’ve always slipped in some exception or bug that made the function a piece of junk. But I recently found an easy solution I hope I could call “definitive”.

Clean url generators are crucial for search engine optimization or just to tidy up the site navigation. They are even more important if you work with international characters, accented vowels /à, è, ì, .../, cedilla /ç/, dieresis /ë/, tilde /ñ/ and so on.

First of all we need to strip all special characters and punctuation away. This is easily accomplished with something like:

function toAscii($str) {
	$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
	return $clean;
}

With our toAscii function we can convert a string like “Hi! I’m the title of your page!” to hi-im-the-title-of-your-page. This is nice, but what happens with a title like “A piñata is a paper container filled with candy”?

The result will be a-piata-is-a-paper-container-filled-with-candy, which is not cool. We need to convert all special characters to the closest ascii character equivalent.

There are many ways to do this, maybe the easiest is by using iconv.

setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str) {
	$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
	$clean = preg_replace("/[^a-zA-Z0-9\/_| -]/", '', $clean);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_| -]+/", '-', $clean);
	return $clean;
}

I always work with UTF-8 but you can obviously use any character encoding recognized by your system. The piñata text is now transliterated into a-pinata-is-a-paper-container-filled-with-candy. Lovable.

If they are not Spanish, users will hardly search your site for the word piñata, they will most likely search for pinata. So you may want to store both versions in your database. You may have a title field with the actual displayed text and a slug field containing its ascii version counterpart.

We can add a delimiter parameter to our function so we can use it to generate both clean urls and slugs (in newspaper editing, a slug is a short name given to an article that is in production, source).

setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $delimiter='-') {
	$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
	$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
	return $clean;
}
// echo toAscii("A piñata is a paper container filled with candy.", ' ');
// returns: a pinata is a paper container filled with candy

There’s one more thing. The string “I’ll be back!” is converted to ill-be-back. This may or may not be an issue depending on your application. If you use the function to generate a searchable slug for example, looking for “ill” would return the famous Terminator quote that probably isn’t what you wanted.

setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
	if( !empty($replace) ) {
		$str = str_replace((array)$replace, ' ', $str);
	}
	$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
	$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
	return $clean;
}

You can now pass custom delimiters to the function. Calling toAscii("I'll be back!", "'") you’ll get i-ll-be-back. Also note that the apostrophe is replaced before the string is converted to ascii as character encoding conversion may lead to weird results, for example é is converted to 'e, so the apostrophe needs to be parsed before the string is mangled by iconv.

The function seems now complete. Lets stress test it.

echo toAscii("Mess'd up --text-- just (to) stress /test/ ?our! `little` \\clean\\ url fun.ction!?-->");
returns: messd-up-text-just-to-stress-test-our-little-clean-url-function
echo toAscii("Perché l'erba è verde?", "'"); // Italian
returns: perche-l-erba-e-verde
echo toAscii("Peux-tu m'aider s'il te plaît?", "'"); // French
returns: peux-tu-m-aider-s-il-te-plait
echo toAscii("Tänk efter nu – förr'n vi föser dig bort"); // Swedish
returns: tank-efter-nu-forrn-vi-foser-dig-bort
echo toAscii("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ");
returns: aaaaaaaeceeeeiiiidnooooouuuuyssaaaaaaaeceeeeiiiidnooooouuuuyy
echo toAscii("Custom`delimiter*example", array('*', '`'));
returns: custom-delimiter-example
echo toAscii("My+Last_Crazy|delimiter/example", '', ' ');
returns: my last crazy delimiter example

I’m sure we are far from perfection and probably some php/regex guru will soon bury me under my ignorance suggesting an über-simple alternative to my function. What do you thing?

w3c validators

Leggendo l’ormai famoso articolo di Robin Good (e anche per esperienza diretta) ho scoperto che rendere un sito accessibile sul web può essere davvero una sfida estenuante, ma grazie agli strumenti che tra un attimo t’ illustrerò, il tuo sito avrà sicuramente quella marcia in più che può fare la differenza!
Devi sapere che le tecnologie utilizzate per creare i siti web, cosi come i protocolli internetsono definiti da alcuni standard ai quali bisogna attenersi per assicurarsi di avere un sito (dal punto di vista del codice) in regola.

Sono certo che ti starai chiedendo chi crea questi standard e come fare per attenersi ad essi… bene devi sapere che questi standard sono creati dal W3C (Word Wide Web Consortium) il W3C è un consorzio internazionale senza fini di lucro, che ha il compito di definire gli standard condivisi per il funzionamento e la gestione del web.
Vediamo quindi come sfruttare gli strumenti offerti da W3C per assicurarti di avere un codice conforme agli standard!

Per le tue pagine che contengono marcatori HTML, XHTML, SMIL, MathML, etc puoi utilizzare il validatore di marcatori

w3c
Come puoi vedere è semplicissimo da usare! Basta inserire l’indirizzo del tuo sito e cliccare sul pulsante Check oppure puoi scegliere di inviare un file da analizzare nel caso il tuo sito non sia online cliccando sulla tab Validate by File Upload, o ancora puoi inserire direttamente il codice da analizzare cliccando sulla tab Validate by Direct Input.

Un altro strumento utilissimo che W3C ti mette a disposizione è il Link Checker che verifica la validità di tutti i link presenti all’indirizzo immesso!
Per i tuoi RSS feed invece w3c ti mette a disposizione il Feed Validator; anche in questo caso ti basterà inserire il link dei tuoi feed e cliccare sul pulsante Check.
Per i tuoi fogli di stile CSS invece puoi utilizzare il CSS Validator sempre con la stessa facilità d’utilizzo degli altri strumenti

Non poteva mancare poi uno strumento per la convalida dei tuoi file XML ecco quindi che w3c mette a tua disposizione l’XML Schema Validator questo validator ti mette a disposizione due modalità di utilizzo: link o file.

Ognuno degli strumenti che ti ho illustrato ti fornirà un dettagliato report sui problemi rilevati e alcune indicazioni per risolverli, e tutto questo a costo 0!

via http://www.squirob.com

stampante bloccata

Stampante
È sufficiente creare un file .bat e farlo partire all’occorrenza, con questo codice:

@echo off
net stop spooler
del %systemroot%\system32\spool\printers\*.shd
del %systemroot%\system32\spool\printers\*.spl
net start spooler

Come sbloccare la coda di stampa della vostra stampante
Sarà capitato anche voi che la stampante si blocchi sulla coda di stampa; questo crea l’impossibilità di continuare a stampare ed appare l’icona di una stampante sulla barra delle applicazioni (vicino all’orologio). Se si apre la finestra si vedrà che la coda di stampa è bloccata.
Solitamente si tenta di annullare sospendendo o eliminando l’operazione di stampa che blocca tutte le seguenti con un risultato vano: vi è però una soluzione, riavviare lo spooler di stampa.
Per fare ciò basta aprire il prompt dei comandi (Start/Esegui: cmd) e digitare quanto segue:
net stop spooler
Dopo aver dato “invio” come risposta riceverete: Servizio Spooler di stampa arrestato. Ora lo spooler si è arrestato, per poter stampare dobbiamo riavviarlo digitando:
net start spooler
Se tutto ciò è troppo lungo, potete creare un file di batch (.bat), ovvero un eseguibile pronto all’uso.
Basta scrivere in un file di testo, quanto segue:
@echo off
net stop spooler
net start spooler
Salvatelo come .bat e non .txt, magari nominandolo in maniera da ricordarlo per esempio: “Ripristina_coda_di_stampa.bat”
Salvatelo dove vi è più comodo ed avviatelo ogni volta che si presenta la necessità di sbloccare la coda di stampa.

via: www.pc-facile.com | dany21.wordpress.com

aggiornamento via: support.microsoft.com

xampp su ubuntu

per quanto riguarda XAMPP è più semplice di quanto pensassi:
http://ubuntuforums.org/showthread.php?t=223410
This is a how-to for setting up a web development environment easily. This guide will install the XAMPP lampp stack into /opt, setup an easy way to start it up and shut it down, and link a folder in your home directory to the webserver.

WARNING
This guide is aimed at a development environment only and should not be used as a public webserver. To setup a public webserver follow the directions on the Ubuntu wiki https://help.ubuntu.com/community/ApacheMySQLPHP

As this is Ubuntu, all the major parts of a typical web server are included (in the main repo, or on the Ubuntu Server CD) and this is a great way to setup a server. The ubuntu developers have prepared a great web server and have made the process as seemless as possible.

But what if even the official way is still to complicated? What if you just want a quick web server for development?

Fortunately there is the XAMPP project: http://www.apachefriends.org/en/xampp.html. The XAMPP project bundles Apache, PHP4 & 5, Perl, mySQL, and a bunch of other utilities/applications into an simple package for Mac OSX, Windows, Solaris, and Linux. Obviously this HOWTO only deals with the linux version.

For those of you with already existing Apache/mySQL/php installations it installs everything into /opt so it doesn’t conflict with any other installation, and it is completely setup and ready to run.

Install XAMPP
Two easy steps:
– Download the most recent version of XAMPP: (at time of writing 1.6.7)
http://prdownloads.sourceforge.net/xampp/xampp-linux-1.6.7.tar.gz?download
(Source URL: http://www.apachefriends.org/it/xampp-linux.html#374)
– Extract the archive to /opt using sudo: (make sure you are in the directory that you downloaded the archive to)

sudo tar xvfz xampp-linux-1.6.7.tar.gz -C /opt

Start XAMPP
To start it up, open a terminal and type this:

sudo /opt/lampp/lampp start

Stop XAMPP
To stop it, open a terminal and type this:

sudo /opt/lampp/lampp stop

Additional XAMPP commands
To see additional commands, open a terminal and type this:

sudo /opt/lampp/lampp

Sweet XAMPP Control Panel

img108.imageshack.us/img108/5647/screenshotxamppcontrolpanelfj6.png

To use the sweet gtk/python control panel:
Run in a terminal:

gedit ~/.local/share/applications/xampp-control-panel.desktop

Paste the following into the open file and save and exit.

[Desktop Entry]
Comment=Start/Stop XAMPP
Name=XAMPP Control Panel
Exec=gksudo "python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py"
Icon[en_CA]=/usr/share/icons/Tango/scalable/devices/network-wired.svg
Encoding=UTF-8
Terminal=false
Name[en_CA]=XAMPP Control Panel
Comment[en_CA]=Start/Stop XAMPP
Type=Application
Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg

“XAMPP Control Panel” will show up in your applications menu under Internet. Use the Alacarte Menu Editor to move it around.

Test to see if XAMPP is running
Once XAMPP is up and running open firefox and go to: http://localhost/

You should see the XAMPP test page:
static.apachefriends.org/images/380.jpg

Location of files and uploading
XAMPP by default uses /opt/lampp/htdocs as the root web directory. The easiest way to start working on files is to link a folder in your home directory into this directory.
My user name is peter so I have /home/peter/public_html linked to /opt/lampp/htdocs/peter. So if I navigate to http://localhost/peter/ I get a listing of all the files/folders in that directory. (As long is there isn’t a index.php/html/etc file)
To set this up, run in a terminal:
– Make public_html directory in home directory:

mkdir ~/public_html

– Link to /opt/lampp/htdocs

sudo ln -s ~/public_html /opt/lampp/htdocs/$USER

Now any files and folders you place in ~/public_html will be published to your personal webserver.
Bookmark http://localhost/username to make this easy to access.

WARNING – SECURITY
http://www.apachefriends.org/en/xampp-linux.html#381

Open holes:
– The MySQL administrator (root) has no password.
– The MySQL daemon is accessible via network.
– ProFTPD uses the password “lampp” for user “nobody”.
– PhpMyAdmin is accessible via network.
– Examples are accessible via network.
– MySQL and Apache running under the same user (nobody).

This doesn’t leave your whole system wide open, but someone could hack your XAMPP installation, so be wary.
To fix most of the security weaknesses open a terminal and run:

sudo /opt/lampp/lampp security

Feedback
Please read this post.

—- EDIT – July 28, 2006 —-
Minor Edits
—- EDIT – August 1, 2006 —-
Re-did xampp control panel shortcut to make it easier.
—- EDIT – August 16, 2006 —-
Added warning for public web servers and edited intro to make it more accurate.
—- EDIT – September 1, 2006 —-
Added sudo to security command.

Rimuovere collegamenti ipertestuale in Word

Word
avete appena fatto copia-incolla da wikipedia a MS Word, ma tutti i richiami ai vari lemma vi rompono le balle? si danno fastidio anche a me, viva google e viva DonNetHell:

Se avete un documento di Word pieno di collegamenti ipertestuali, ma volete rimuoverli lasciando inalterato il testo che conteneva il link:
– Selezionate la parola o tutto il testo
– Premete CTRL-SHIFT-F9
Ed ecco il vostro testo senza collegamenti

fonte: http://blogs.dotnethell.it/