View previous topic :: View next topic |
Author |
Message |
ciri Smarty Rookie
Joined: 12 Dec 2007 Posts: 7
|
Posted: Wed Dec 12, 2007 10:58 am Post subject: caratteri speciali e smarty |
|
|
Salve a tutti!
Se visualizzo il file PROVA.HTML così fatto:
Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body><p>Questa è una prova</p></body>
</html>
|
...ottendo la visualizzazione della "è" corretta.
Se invece utilizzo smarty e quindi utilizzo un file php così fatto:
Code: |
<?php
// caricamento delle librerie di Smarty
require('./smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = './smarty/site/templates';
$smarty->compile_dir = './smarty/site/templates_c';
$smarty->config_dir = './smarty/site/configs';
$smarty->cache_dir = './smarty/site/cache';
$smarty->display('prova.tpl');
?>
|
...che richiama un file prova.tpl così fatto:
Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body><p>Questa è una prova</p></body>
</html>
|
...ottendo la visualizzazione della "è" NON corretta. Al suo posto ho un "?"
Che senso ha? Sapete suggerirmi il possibile problema?
Grazie a chi mi vorrà aiutare! |
|
Back to top |
|
flatfield Smarty Rookie
Joined: 30 Apr 2007 Posts: 18 Location: Genova (Italy)
|
Posted: Wed Dec 12, 2007 11:21 am Post subject: |
|
|
Uhm... non mi è mai capitata questa cosa...
Entrambi i file sono stati creati con lo stesso editor? In altre parole: sei sicuro che tutti i file siano stati salvati in utf-8?
E' importante controllare questo fatto, perchè se il file non è salvato in utf-8 e lo forzi con il "Content-Type" a visualizzarsi come utf-8, poi non si vedrà correttamente
Last edited by flatfield on Wed Dec 12, 2007 11:57 am; edited 1 time in total |
|
Back to top |
|
ciri Smarty Rookie
Joined: 12 Dec 2007 Posts: 7
|
Posted: Wed Dec 12, 2007 11:25 am Post subject: |
|
|
Ho realizzato il tutto con eclipse.
Scusa la domanda.. ma come faccio a verificare se il file è salvato in utf8? Come faccio a salvare in utf-8 da eclipse? |
|
Back to top |
|
ciri Smarty Rookie
Joined: 12 Dec 2007 Posts: 7
|
Posted: Wed Dec 12, 2007 11:49 am Post subject: |
|
|
Hai ragione! Ho provato a creare il file prova.tpl con blocco note e impostare la codifica a utf-8. Così torna. Grazie della dritta! |
|
Back to top |
|
flatfield Smarty Rookie
Joined: 30 Apr 2007 Posts: 18 Location: Genova (Italy)
|
Posted: Wed Dec 12, 2007 11:57 am Post subject: |
|
|
ciri wrote: | Hai ragione! Ho provato a creare il file prova.tpl con blocco note e impostare la codifica a utf-8. Così torna. Grazie della dritta! |
Figurati!
Comunque su Eclipse il settaggio della codifica è in:
"Project" -> "Properties" -> "Resource" -> "Text file encoding" |
|
Back to top |
|
ciri Smarty Rookie
Joined: 12 Dec 2007 Posts: 7
|
Posted: Wed Dec 12, 2007 1:37 pm Post subject: |
|
|
Questa parte è ok!
Adesso, però, ho un altro problemino..
Se voglio recuperare il contenuto della mia pagina da db mysql e poi passarlo a smarty, ho lo stesso problema sui caratteri accentati.
LA MIA SITUAZIONE E':
db mysql con collation "utf8-general_ci"
tabella che contiene il testo da estrarre con collation "utf8-general_ci"
la stessa codifica "utf8-general_ci" è impostata su tutti i campi testo della mia tabella
ESEMPIO:
la TABELLA contiene: "Questo è il testo da estrarre"
Il risualtato che otttengo è: "Questo ? il testo da estrarre"
Non capisco il problema! Pensavo che impostando la codifica come ho fatto da phpmyadmin sul db non ci sarebbero stati problemi..
Come potrei risolvere? |
|
Back to top |
|
ciri Smarty Rookie
Joined: 12 Dec 2007 Posts: 7
|
Posted: Wed Dec 12, 2007 2:28 pm Post subject: |
|
|
Ecco ho risolto!
Ho provato a fare l'inserimento da script.. e non da phpmyadmin. Poi a riestrarre la stringa e quindi visualizzarla.
Visualizzo la lettera accentata correttamente!
A quanto pare non c'è da fidarsi di phpmyadmin.. |
|
Back to top |
|
mellowonpsx Smarty Rookie
Joined: 03 Jan 2008 Posts: 5
|
Posted: Fri Jan 04, 2008 8:50 am Post subject: |
|
|
scusate, ma l'uso dei caratteri speciali ed accentati non è W3C.
Quindi dovreste utilizzate è ò etc etc etc.
Per ovviare a questo problema Smarty ha degli stumenti (nel manuale "Chapter 5. Variable Modifiers") che permettono di fare una conversione automatica del contenuto di una variabile.
Direi che in questo caso:
Code: | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body><p>{$testo|escape}</p></body>
</html> |
dove $testo è una variabile di smarty, oppure se il testo è statico
Code: | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body><p>Questa è una prova</p></body>
</html> |
ecco tutti i caratteri con la loro forma "escaped": www.theukwebdesigncompany.com/articles/entity-escape-characters.php |
|
Back to top |
|
raoh980 Smarty Rookie
Joined: 13 May 2008 Posts: 7
|
Posted: Tue May 13, 2008 10:23 pm Post subject: |
|
|
molto interessante !! |
|
Back to top |
|
|