Search code examples
phpxmllimitfetch

make limit of content when getting data from xml to php


Hello guys i'm getting data from xml to php and i want to make limit. for example get only 10 post down is a examples of my xml file and php code

This is xml file from where i'm getting data : http://myscandal.ge/sitemap.xml

And there is a php code, so i'm getting data from xml file :

http://mymus.ge/example.txt


Solution

  • Put a counter inside your foreach loop and break when it reaches the limit you want. Something like

    $countrer = 0;
    foreach(..){ 
       // your code here
      $counter++; 
      if($counter == X) break;
    }
    

    Where X the number of results you want.