Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    problema lettere accentate da file xml a php

    Buongiorno a tutti, ho questo file xml:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <MENU>
    <word><it>bontà </it><en>goodness</en></word>
    </MENU>

    e questo file php:
    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <?PHP header('Content-type: text/html; charset=iso-8859-1'); ?>
    <head>
    <style>
    body {
    font-family: "Times New Roman OS";
    font-weight: 100;
    font-size:24px;
    background-color:#333;
    text-align:center;
    }

    input {
    padding:5px;
    background-color:#222;
    color:#bbb;
    border:0;
    font-style: italic;
    margin:6px 0;
    height:30px;
    }
    </style>
    </head>

    <body>
    <?PHP
    $documento = new DOMDocument();
    $documento->load( 'file.xml' );

    $elementi = $documento->getElementsByTagName( "word" );
    $num=0;
    $wordit = array();

    foreach( $elementi as $elemento ){
    $num=$num+1;
    $nomelemento = $elemento->getElementsByTagName( "it" );
    $wordit[$num] = $nomelemento->item(0)->nodeValue;

    $nomelemento = $elemento->getElementsByTagName( "en" );
    $worden[$num] = $nomelemento->item(0)->nodeValue;
    }

    $randomlingua = rand(1,2);
    $randomword = rand(1,$num);
    ?>

    <div style="border:2px dashed #999; padding:10px; width:400px; margin:200px auto 0 auto;">
    <?PHP if ($randomlingua == 1) { ?>
    <span style="color:#fff; font-style: italic;"><?PHP echo $wordit[$randomword];?> (ita)</span><br><input type="text" size="50" placeholder="write text">
    <span style="color:#333;"><?PHP echo $worden[$randomword];?></span><br>
    <?PHP } else { ?>
    <span style="color:#007bba; font-style: italic;"><?PHP echo $worden[$randomword];?> (eng)</span><br><input type="text" size="50" placeholder="write text">
    <span style="color:#333;"><?PHP echo $wordit[$randomword];?></span><br>
    <?PHP } ?>
    </div>

    </body>
    </html>

    Ma mi interpreta male gli accenti. Come posso fare? Ho provato anche in UTF8 ma la situazione non migliora.
    Ci sono delle funzioni (tipo htmlentities) che risolvono il problema? se si, come?
    grazie
    Martino

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Benvenuto.
    Leggi il mio link in firma sui caratteri strani.

  3. #3
    Quote Originariamente inviata da Alhazred Visualizza il messaggio
    Benvenuto.
    Leggi il mio link in firma sui caratteri strani.
    Grazie mille,era proprio il salvataggio del file che andava fatto anch'esso in utf8, mitico!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.