Snippet PHP + CSS: HTML Maiuscoletto

Blog - Snippets

Questo è un semplicissimo codice PHP utile per creare un effetto "Maiuscoletto" per i una stringa.

Adagio => ADAGIO il risultato è visibile solo se avete una classe smaller definita nel vostro css.

codice php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 *
 * (c)2011 SFS.it, All rights reserved
 * License: http://www.sfs.it/licenza-bsd44.html
 * Use and modify all you want just keep this comment. Thanks
 *
 **/
 
/**
 *
 * function html_capitalize
 * parameters:
 *    $text: testo da convertire
 *
 **/
function html_capitalize($text) {
	$substr='';
	$return='';
	for ($c=0,$len=strlen($text); $c < $len; $c++) {
		$ch = $text[$c];
		if ($ch >= 'a' && $ch <= 'z')
			$substr.=$ch;
		else {
			if (!empty($substr)){
				$return.='<span class="smaller">'.strtoupper($substr).'</span>';
				$substr='';
			}
			$return.=$ch;
		}
	}
	if (!empty($substr))
		$return.='<span class="smaller">'.strtoupper($substr).'</span>';
	return $return;
}

codice css:

.smaller {
	font-size: smaller;
}

 

Ultimo aggiornamento (Domenica 01 Maggio 2011 23:19)

 

Aggiungi commento


Codice di sicurezza
Aggiorna