0
I’m using the base feed file from google, and need to change the information dynamically to generate an xml file, I am using this approach, with file_puts_contents(), to put the tags <item>
in the archive:
file_put_contents('feed.xml', $xml, FILE_APPEND);
only that the end of the xml file has to end with this structure:
</channel>
</rss>
and FILE_APPEND is putting below it, is there any way to insert the content in a specific location or always add the </channel></rss>
at the end of the loop?
EDIT: Xml standard google:
<?xml version="1.0"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>O nome do feed de dados</title>
<link>http://www.example.com</link>
<description>Uma descrição do conteúdo</description>
<item>
<title>Suéter de lã vermelho</title>
<link> http://www.example.com/item1-info-page.html</link>
<description>Confortável e macio, este suéter manterá você aquecido nas noites frias do inverno.</description>
<g:image_link>http://www.example.com/image1.jpg</g:image_link>
<g:price>25</g:price>
<g:condition>novo</g:condition>
<g:id>1a</g:id>
</item>
</channel>
</rss>
What would be "below that"? If you want to put at the end of the file, wouldn’t they actually be below the rest of the content? That part was very confusing.
– Woss
below the xml closure , with the tags Channel and rss
– Thiago
You have to [Edit] the question and put how the XML should look and how it comes from feed google?
– Woss
Right, but the link I put up is the google template.
– Thiago
But in this template there are already the tags you want to insert. What is the code you are using to generate this new XML and how it is getting?
– Woss
I’ll use a loop to insert database data.
– Thiago
Put it to try to make the problem more understandable. For now it is very confusing.
– Woss
is a simple foreach using file_put_contents, the problem is just to put the closure in the last loop
– Thiago
And why don’t you put it out of the loop after it? It will only run when the loop ends.
– Woss
I hadn’t even thought about it, I’ll test it, thank you
– Thiago