View previous topic :: View next topic |
Author |
Message |
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Tue Mar 16, 2010 9:36 am Post subject: display a data with smarty is not correct |
|
|
hello
I used query to get data from oracle, i used tow method to display this data such as:
Code: | $nrows = oci_fetch_all($stid, $data_res, null, null, OCI_FETCHSTATEMENT_BY_ROW); |
first with php file:
Code: |
foreach ($data_res as $col) {
echo "<tr>\n";
foreach ($col as $item) {
echo " <td>".($item !== null ? htmlspecialchars($item, ENT_QUOTES) : " ")."</td>\n";
}
echo "</tr>\n";
}
|
I got correct data display
second with smarty file, I am passing data to the mStudent variable:
Code: |
{section name=i start=0 loop=$mStudent}
<tr>
<td>{$mStudent[i].id}</td>
<td>{$mStudent[i].first_name}</td>
<td>{$mStudent[i].second_name}</td>
<td>{$mStudent[i].email}</td>
<td>{$mStudent[i].NOTE}</td>
</tr> |
data characters appear in an illegible such as :
I use utf8 charset
When I used escape like ($mStudent[i].first_name|escape) the data disappear
when i used escape like ($mStudent[i].first_name|escape:'htmlall') the data display as Incomprehensible char such as:
can any one resolve this problem?
thanks |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Mar 16, 2010 2:36 pm Post subject: |
|
|
Smarty 2 or 3? Do you have multibyte support installed in PHP? |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Wed Mar 17, 2010 8:11 am Post subject: |
|
|
thanks
I use Smarty v2.6.9 and php version 5.2.8
Multibyte Support : enabled |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 17, 2010 12:55 pm Post subject: |
|
|
Try the latest smarty release first, 2.6.9 is quite old. |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Wed Mar 17, 2010 2:33 pm Post subject: |
|
|
a same result!
thanks |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 17, 2010 2:36 pm Post subject: |
|
|
So you are saying in PHP:
shows correctly, and if you do:
Code: | $smarty->assign('myvar',$myvar'); |
I does not display right? Can you do this quick test? |
|
Back to top |
|
SoN9ne Smarty Rookie
Joined: 25 Feb 2010 Posts: 17
|
Posted: Wed Mar 17, 2010 11:36 pm Post subject: |
|
|
What is your database collation?
Did you setup a new database and inject data from an older one into it?
I have seem this a few times and it was due to a database with a different encoding (latin_swedish_1) being injected into a new database with a utf-8 collation. |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Thu Mar 18, 2010 7:32 am Post subject: |
|
|
thank you very much
yes I'm sure, without smarty i got this result:
I have discovered something new, when I change the encoding in your browser to Arabic (Windows) shows the data are correct, while everything else in the page (wrote with arabic) appears incorrectly such as this image:
in smarty file i use utf8, and database utf8 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 18, 2010 1:20 pm Post subject: |
|
|
Do you have a meta tag in the browser that sets the charset you want? |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Thu Mar 18, 2010 1:24 pm Post subject: |
|
|
yes i have it, i use two: Internet explorer and firefox |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 18, 2010 1:26 pm Post subject: |
|
|
If you switch the encoding to Arabic and it looks right, that makes me think the charset is not UTF8, but Arabic. Are you setting the charset to Arabic in the meta tag? |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Thu Mar 18, 2010 1:37 pm Post subject: |
|
|
no, my browser auto-select lanaguage, but i try to select arabic/utf-8 to view data is correct (manual)!
and i save my file as : unix|utf-8 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 18, 2010 1:51 pm Post subject: |
|
|
does the text look right if you take Smarty out of the picture and just display straight from PHP? My guess is Smarty is not causing any of this. |
|
Back to top |
|
ahoussam Smarty Rookie
Joined: 26 Jan 2010 Posts: 16
|
Posted: Thu Mar 18, 2010 1:57 pm Post subject: |
|
|
Completely, with PHP appear correctly, as in the previous image! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 18, 2010 2:58 pm Post subject: |
|
|
So as in my test above:
shows correctly?
And then:
Code: | $smarty->assign('myvar',$myvar'); |
Does not show correctly? It should since Smarty does nothing to the text and just echos it, much the same as PHP. |
|
Back to top |
|
|