0
How do I convert it (which only brings me the first photo)
//corrige foto
$enderecofoto = $xml->imovel[$i]->fotos->foto;
$nomeeextensao = preg_replace("(^.*\/(.*)\$)", "$1$2",$enderecofoto);
$removenomeeextensao = str_replace($nomeeextensao, "", $enderecofoto);
$nomefoto = substr($nomeeextensao, 0 , (strrpos($nomeeextensao, ".")));
//remove antiga tag antes de adicionar a nova, para evitar remoção de ambas
unset($xml->imovel[$i]->fotos->foto);
$foto = $xml->imovel[$i]->fotos->addChild('foto');
$foto->addAttribute('path', $removenomeeextensao);
$foto->addAttribute('arquivo', $nomeeextensao);
$foto->addAttribute('titulo', $nomefoto);
In a loop?
My script is basically this, and this "conversion" would be there:
$xml=simplexml_load_file("feed.xml") or die("Error: Cannot create object");
for ($i = 0; $i < count($xml); $i++) {
@@@@AQUI@@@@
}
echo $xml->asXML();
$xml->asXML('xml.xml');
The Loop should result in:
<fotos>
<foto path="http://localhost:8090/images/" arquivo="1.jpg" titulo="1"/>
<foto path="http://localhost:8090/images/" arquivo="2.jpg" titulo="2"/>
<foto path="http://localhost:8090/images/" arquivo="3.jpg" titulo="3"/>
</fotos>
Instead of (what is currently):
<fotos>
<foto path="http://localhost:8090/images/" arquivo="1.jpg" titulo="1"/>
</fotos>
What do you say?
Looking at the Stackoverflow I found this:
foreach($xml->imovel[$i]->fotos->foto as $foto) { 
  if(isset($xml->imovel[$i]->fotos->foto)) {
    $fotos = array();
    foreach ($xml->imovel[$i]->fotos->foto as $foto) {
      $fotos[] = "$foto"; 
      // or you could use, I believe: $fotos[] = $foto[0] 
    }
  } 
  else $fotos = "";
  var_dump($fotos); 
  echo "<hr />"; 
}
But how do I make this foreach use my settings? For a new XML tag to receive the data as it was set in the config I did upstairs?
--------------EDIT
    foreach($xml->imovel[$i]->fotos->foto as $foto) { 
      if(isset($xml->imovel[$i]->fotos->foto)) {
        $fotos = array();
        foreach ($xml->imovel[$i]->fotos->foto as $foto) {
          $fotos[] = "$foto"; 
          $nomeeextensao = preg_replace("(^.*\/(.*)\$)", "$1$2",$foto);
          $removenomeeextensao = str_replace($nomeeextensao, "", $foto);
          $nomefoto = substr($nomeeextensao, 0 , (strrpos($nomeeextensao, ".")));
          $fotoxml = $xml->imovel[$i]->fotos->addChild('foto');
          $fotoxml->addAttribute('path', $removenomeeextensao);
          $fotoxml->addAttribute('arquivo', $nomeeextensao);
          $fotoxml->addAttribute('titulo', $nomefoto);
        }
      } 
      else $fotos = "";
      var_dump($fotos); 
      echo "<hr />"
; 
}
						
Very interesting, in your case you used a mysql query as an array. I will try to use this foreach idea and modify mine. Thanks a lot :D
– Diego
It’s.... Unfortunately it’s not working out so well.... :(
– Diego
@Diego. Which error returned to you?
– Igor Silva
Allowed memory size of 134217728 bytes exhausted (tried to allocate 40 bytes). Or Execution time.... 90 Seconds. I will edit the main topic with the code I used.
– Diego
There is something related to your error at this link:(http://stackoverflow.com/questions/561066/fatal-error-allowed-memory-sizof-134217728-bytes-exhausted-codeigniter-xml). However, post the code you are running.
– Igor Silva
Already posted, is in EDIT in the main post. Take a look.
– Diego