Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_xml($xmlUrl, $articles) {
- function objectsIntoArray($arrObjData, $arrSkipIndices = array()) {
- $arrData = array();
- // if input is object, convert into array
- if (is_object($arrObjData)) {
- $arrObjData = get_object_vars($arrObjData);
- }
- if (is_array($arrObjData)) {
- foreach ($arrObjData as $index => $value) {
- if (is_object($value) || is_array($value)) {
- $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
- }
- if (in_array($index, $arrSkipIndices)) {
- continue;
- }
- $arrData[$index] = $value;
- }
- }
- return $arrData;
- }
- $xmlStr = file_get_contents($xmlUrl);
- $xmlObj = simplexml_load_string($xmlStr);
- $arrXml = objectsIntoArray($xmlObj);
- $i = 0;
- foreach($arrXml['Assignments']['Assignment'] as $item) {
- echo '<ul class="parserItem">';
- echo '<li><span>'.$item['MunicipalityName'].'</span></li>';
- echo '................'
- echo '</ul>';
- if (++$i == $articles+1) break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement