-1
Hello,
I’m looking for a solution to query information within an XML, I found a tutorial on the internet, but the code is with an error that I can not solve.
The code is this:
<?php
# Carrega e armazena o XML na variavel $xml
$xml = simplexml_load_file(“estante.xml”);
# laço dentro da tag livro para cada tag livro que encontrar
foreach($xml->xpath(‘//livro‘) as $livro)
{
# armazena na var $registro o conteudo de uma tag livro
$registro = simplexml_load_string($livro->asXML());
# executa uma consulta XPath e armazena em $busca
$busca = $registro->xpath(‘//preco[.>55.00]‘);
# verificando se houve alguma busca com sucesso
if($busca){
# exibindo os resultados encontrados
echo $livro->titulo . “<br>”;
echo $livro->descricao . “<br>”;
echo $livro->preco . “<br><br>”;
}
}
?>
The XML he queries is this:
<?xml version=”1.0″ encoding=”iso-8859-1″?>
<livros>
<livro>
<cod>01</cod>
<titulo>PHP para iniciantes</titulo>
<descricao>Desenvolvendo Aplicações web</descricao>
<autor>Manuel da Silva</autor>
<paginas>200</paginas>
<preco>50.00</preco>
</livro>
<livro>
<cod>02</cod>
<titulo>XML</titulo>
<descricao>Usando XML com PHP </descricao>
<autor>José das Couves</autor>
<paginas>100</paginas>
<preco>150.00</preco>
</livro>
<livro>
<cod>03</cod>
<titulo>Javascript</titulo>
<descricao>O Poder do javascript</descricao>
<autor>Billy Borny</autor>
<paginas>80</paginas>
<preco>90.90</preco>
</livro>
</livros>
The error I receive as return is an error on Line 6 with this information:
[19-Feb-2019 15:22:22 UTC] PHP Parse error: syntax error, unexpected '{', expecting ',' or ')' in /home3/smarts43/public_html/app/index.php on line 6
I believe it should be a simple mistake, if someone has a light to help me, I have already followed the guidelines that it returns, but the error persists.
Thank you,
I did not understand the purpose of the two bars in the line of the
foreach? Is that how your code is? If it is, you’re opening parentheses, and you’re not closing because the rest of the line is commented.– Vinicius De Jesus