Jump to content

Variavel php dentro de tag xml


Recommended Posts

Posted

Olá,

Eu estou a fazer um site com vários idiomas (usando o smarty), onde as frases/palavras estão num ficheiro xml. Por exemplo:

<?xml version="1.0" encoding="utf-8"?>
<languages>
  <pt>
    <title>Português</title>
  </pt>
  <eng>
    <title>English</title>
  </eng>
</languages>

E para chamar a tag que quero faço:

$xml = simplexml_load_file("lang/languages.xml");
$smarty->assign("language", $xml->$language);

Até hoje estava tudo a correr às mil maravilhas, mas agora precisei de inserir uma variavel php no meio de uma frase. Exemplo:

<?xml version="1.0" encoding="utf-8"?>
<languages>
  <pt>
    <title>Português - $hours horas.</title>
  </pt>
  <eng>
    <title>English - $hours hours.</title>
  </eng>
</languages>

Agora gostaria de saber como é que mostro o valor da variável $hours na frase ("Português - 11 horas"), em vez de aparecer "$hours" ("Português -$hours horas").

Cumprimentos,

Caya

Posted

ou defines "a mão" por exemplo <?php echo($horas); ?> ou fazes replace, str_replace('$horas',funcaoQueRetornaHoras(),$xmlContent) ou com ob e depois eval da cena, ou usares xslt.... sei la... existem tantas formas...

"Quando eu for grande quero ser como o Celso"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.