Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

caratteri speciali e smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian
View previous topic :: View next topic  
Author Message
ciri
Smarty Rookie


Joined: 12 Dec 2007
Posts: 7

PostPosted: Wed Dec 12, 2007 10:58 am    Post subject: caratteri speciali e smarty Reply with quote

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
View user's profile Send private message
flatfield
Smarty Rookie


Joined: 30 Apr 2007
Posts: 18
Location: Genova (Italy)

PostPosted: Wed Dec 12, 2007 11:21 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ciri
Smarty Rookie


Joined: 12 Dec 2007
Posts: 7

PostPosted: Wed Dec 12, 2007 11:25 am    Post subject: Reply with quote

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? Sad
Back to top
View user's profile Send private message
ciri
Smarty Rookie


Joined: 12 Dec 2007
Posts: 7

PostPosted: Wed Dec 12, 2007 11:49 am    Post subject: Reply with quote

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! Wink
Back to top
View user's profile Send private message
flatfield
Smarty Rookie


Joined: 30 Apr 2007
Posts: 18
Location: Genova (Italy)

PostPosted: Wed Dec 12, 2007 11:57 am    Post subject: Reply with quote

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! Wink


Figurati!

Comunque su Eclipse il settaggio della codifica è in:
"Project" -> "Properties" -> "Resource" -> "Text file encoding"
Back to top
View user's profile Send private message Visit poster's website
ciri
Smarty Rookie


Joined: 12 Dec 2007
Posts: 7

PostPosted: Wed Dec 12, 2007 1:37 pm    Post subject: Reply with quote

Questa parte è ok!
Adesso, però, ho un altro problemino.. Confused
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
View user's profile Send private message
ciri
Smarty Rookie


Joined: 12 Dec 2007
Posts: 7

PostPosted: Wed Dec 12, 2007 2:28 pm    Post subject: Reply with quote

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! Smile

A quanto pare non c'è da fidarsi di phpmyadmin..
Back to top
View user's profile Send private message
mellowonpsx
Smarty Rookie


Joined: 03 Jan 2008
Posts: 5

PostPosted: Fri Jan 04, 2008 8:50 am    Post subject: Reply with quote

scusate, ma l'uso dei caratteri speciali ed accentati non è W3C.
Quindi dovreste utilizzate &egrave; &ograve; 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 &egrave; 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
View user's profile Send private message
raoh980
Smarty Rookie


Joined: 13 May 2008
Posts: 7

PostPosted: Tue May 13, 2008 10:23 pm    Post subject: Reply with quote

molto interessante !!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP