I would like to print a variable in a method post xml text. Is possible?
<?
$qtdRows = 10; //Ver consulta do banco
$nome = $_POST['nome'];
//ARQUIVO XML CRIADO NO SERVIDOR (Pode ser um arquivo em branco, so para iniciar, e depois ele coloca o conteudo com o script)
$arquivo = "cases.xml";
$escrever .= '<?xml version="1.0" encoding="ISO-8859-1" ?>';
$escrever .= '<filmes>';
for($i=0; $i<$qtdRows; $i++){
$escrever .= '<filme>';
$escrever .= '<nome> $nome </nome>';
$escrever .= '<ano>$ano</ano>';
$escrever .= '<diretor>$diretor</diretor>';
$escrever .= '<comentarios>$filme</comentarios>';
$escrever .= '</filme>';
}
$escrever .= '</filmes>';
$fd = fopen ($arquivo, "w"); // abre o arquivo
fwrite($fd, $escrever); //Escreve no arquivo
fclose ($fd); // fecha o arquivo
?>
<script>
location.href = 'index.php'; //Redirediona, depois de gerado o XML, para qualquer pagina (Ex: index.php)
</script>
this method does not work! What would the correct syntax? $escrever .= '<nome> $nome </nome>';
Change this line:
$escrever .= '<?xml version="1.0" encoding="ISO-8859-1" ?>';
for:
// Without concatenation
$escrever = '<?xml version="1.0" encoding="ISO-8859-1" ?>';
Also, the concatenation should be:
$escrever .= '<nome>' . $nome . '</nome>';
I hope it helps!
.
is used to concatenate strings, as shown here.
$escrever .= '<nome>' . $nome . '</nome>';
(Add the dots .
and the single quotes '
.)
Suerte!