При загрузке XML-файла, если в одном файле есть одна новость. Хорошо, но не один. его создание массива внутри массива. Как я могу получить доступ к этому - PullRequest
0 голосов
/ 03 сентября 2018
$files =  $mediaUrl = '';
$datePrev = date('d')-1;
$FinalDate = ownCheckDate($datePrev);
function ownCheckDate($date)
{
    if (strlen($date)<2) {
        return '0'.$date;   
    }
    else
    {
        return $date;
    }
}
$medUrl = 'ANIFeeds/'.date('Y').'/ANI XML/'.strtolower(date('F')).'/'.date('d').'/';
$Url = 'ANIFeeds/'.date('Y').'/ANI XML/'.strtolower(date('F')).'/'.$FinalDate.'/';
$filepath = $medUrl.'*.xml';
$AltFileUrl = $Url.'*.xml';
$AltFiles = glob($AltFileUrl);
$file = glob($filepath);
if ($file) {
    $files = $file;
    $mediaUrl = $medUrl;
}
else
{
    $files = $AltFiles;
    $mediaUrl = $Url;
}
foreach ($files as $filename) {
    $xml[] = simplexml_load_file($filename);
    foreach ($xml as $key=>$news) {            
        if ($news->article->cats == "Business" || $news->article->cats == "business" || $news->article->cats == "BUSINESS")
        {
                $BusinessData[] = $news;
        } else
       if ($news->article->cats == "National" || $news->article->cats == "national" || $news->article->cats == "NATIONAL") {
                $NationalData[] = $news;
        } else
        if ($news->article->cats == "Travel" || $news->article->cats == "travel" || $news->article->cats == "TRAVEL") {
                $TravelData[] = $news;
        } else
        if ($news->article->cats == "Technology" || $news->article->cats == "technology" || $news->article->cats == "TECHNOLOGY" || $news->article->cats == "tech" || $news->article->cats == "Tech") {
                $TechnologyData[] = $news;
        } else
        if ($news->article->cats == "Sports" || $news->article->cats == "sports" || $news->article->cats == "SPORTS") {
                $SportsData[] = $news;
        } else
        if ($news->article->cats == "LifeStyle" || $news->article->cats == "Lifestyle" || $news->article->cats == "LIFESTYLE" || $news->article->cats == "LIFE STYLE" || $news->article->cats == "life style") {
                $LifeData[] = $news;
        }else 
        if ($news->article->cats == "Entertainment" || $news->article->cats == "entertainment" || $news->article->cats == "ENTERTAINMENT") {
                $EntertainmentData[] = $news;
        }else
        if ($news->article->cats == "World" || $news->article->cats == "world" || $news->article->cats == "WORLD") {
                $WorldData[] = $news;
        }else
        if ($news->article->cats == "Science" || $news->article->cats == "science" || $news->article->cats == "SCIENCE") {
                $ScienceData[] = $news;
        }


    }
}

`

Выход:

Array
(
    [0] => SimpleXMLElement Object
        (
            [article] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [ID] => 201808310156090001
                        )

                    [author] => ANI
                    [headline] => Flood alert in parts of Arunachal Pradesh, Assam
                    [cats] => National
                    [subcats] => Guwahati (Assam) [India]
                    [imagename] => Assam_Aug31.jpg
                    [summary] => Guwahati (Assam) [India], Aug 31 (ANI): Flood alert has been issued in low-lying areas nearing the Siang/ Brahmaputra river in Arunachal Pradesh and Assam after 9020 cumec of water was discharged into Tsangpo river by China on Thursday.
                    [content] => SimpleXMLElement Object
                        (
                            [p] => Array
                                (
                                    [0] => Guwahati (Assam) [India], Aug 31 (ANI): Flood alert has been issued in low-lying areas nearing the Siang/ Brahmaputra river in Arunachal Pradesh and Assam after 9020 cumec of water was discharged into Tsangpo river by China on Thursday.
                                    [1] => The Siang river in Arunachal Pradesh has turned virulent with unusually high waves, according to sources in the Central Water Commission (CWC).
                                    [2] => The East Siang District Administration has cautioned the public to refrain from venturing into Siang River for fishing, swimming and other activities to avoid any eventualities.
                                    [3] => "Chinese Government relayed to Government to Arunachal Pradesh by Government of India states that due to heavy rainfall in Chinese portion the Tsangpo river is swelling with observed discharge of 9020 cumec this morning (Thursday) at 8 am at the various GD station on Tsangpo river which is reported as highest in 50 years," said T Tatak, deputy commissioner, East Siang District, Pasighat, Arunachal Pradesh.
                                    [4] => "People living in low lying areas namely Jarku, Paglek, SS Mission, Jarkong, Banskota, Bergung, Sigar, Borguli, Seram, Kongkul, Namsing, Mer are advised to remain alert but no panic due to the situation," Tatak added.
                                    [5] => In view of the flood warning issued by the Assam State Disaster Management Authority, the Dibrugarh District Administration has taken adequate precautionary measures in the district.
                                    [6] => "We are closely monitoring the situation. We have sent our team to various flood prone areas under Chabua revenue circle. If required, we will evacuate people from those areas. We have kept vehicles, boats ready at the vulnerable areas. We have deputed the Circle Officers, Zonal Officers, Sector officers and other officers in all the vulnerable areas to monitor the situation and take necessary measures in case of any eventuality," Deputy Commissioner Loya Maduri said.
                                    [7] => As per reports, the high waves of the river are confined only to the river's reaches in Pasighat and no impact of this changed behaviour of the river has been recorded in the downstream areas of Assam.
                                    [8] => Former Education Minister of Arunachal Pradesh Bosiram Siram said, "Since Wednesday night, the dwellers of adjoining areas of Siang river are panicking about the increase of water level. Most of the people have shifted their base over the night. As per the Central Water Commission, the highest water level recorded (157.54m) was on June 11, 2000. The water level was 153.27m at noon on Thursday. The danger level is 153.960 m. In such position, the commission has given alert to administration for precautionary steps." (ANI)
                                )

                        )

                )

        )

    [1] => SimpleXMLElement Object
        (
            [article] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [ID] => 201808310228590001
                                )

                            [author] => ANI
                            [headline] => 4th Test: Indian pacers restrict England to 246 on Day 1
                            [cats] => Sports
                            [subcats] => London [UK]
                            [imagename] => India_England_Aug31.jpg
                            [summary] => London [UK], August 31 (ANI): Jasprit Bumrah, Ishant Sharma and Mohammed Shami helped India restrict England to 246 on the opening day of the fourth Test at The Ageas Bowl Cricket Ground on Thursday.
                            [content] => SimpleXMLElement Object
                                (
                                    [p] => Array
                                        (
                                            [0] => London [UK], August 31 (ANI): Jasprit Bumrah, Ishant Sharma and Mohammed Shami helped India restrict England to 246 on the opening day of the fourth Test at The Ageas Bowl Cricket Ground on Thursday.
                                            [1] => After losing the first two Tests, India came back strongly in the five-Test series in the third encounter. Continuing their good form, Indian bowlers showcased a disciplined bowling effort and gave a good chance to the batting lineup to take a strong lead over the hosts.
                                            [2] => England lost six wickets for 86 runs to find themselves in a precarious position after opting to bat first. Bumrah (3/46), Ishant Sharma (2/26), Shami (2/51) and spinner R Ashwin (2/40) altogether portrayed a strong bowling attack. All-rounder Hardik Pandya (1/51) also managed to get a wicket.
                                            [3] => Alastair Cook (17), Keaton Jennings (0), Joe Root (4), Jonny Bairstow (6) all got out cheaply thus putting pressure on the middle and the lower order.
                                            [4] => Later, all-rounder Sam Curran anchored the England innings by scoring 78 vital runs as he shared 81 runs with Moeen Ali (40) and 63 runs with Stuart Broad (17) for the seventh and ninth wickets respectively.
                                            [5] => However, the England side didn't manage to build a long partnership thereby getting all-out on 246.
                                            [6] => At stumps, Shikhar Dhawan (3 not out) and KL Rahul (11 not out) were at the crease with the hosts leading by 227 runs. (ANI)
                                        )

                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [ID] => 201808310228590002
                                )

                            [author] => ANI
                            [headline] => Time to reinvent flashback jewellery!
                            [cats] => Lifestyle
                            [subcats] => New Delhi [India]
                            [imagename] => fashion_Aug31.jpg
                            [summary] => New Delhi [India] Aug 31(ANI): The ancestral jewel pieces in one's jewellery collection can be the most personal and expressive accessories with both emotional as well as financial value attached to them.
                            [content] => SimpleXMLElement Object
                                (
                                    [p] => Array
                                        (
                                            [0] => New Delhi [India] Aug 31(ANI): The ancestral jewel pieces in one's jewellery collection can be the most personal and expressive accessories with both emotional as well as financial value attached to them.
                                            [1] => While the prime key to reworking with the ancestral jewels is to suit the current owner's taste, here are some tips and tricks using which the fashionistas can strike a style statement wherever they go:
                                            [2] => Shower some sparkle
                                            [3] => Heritage jewellery includes some precious stones like rubies, emeralds and sapphires, but it's now time to add some fusion to the age-old jewels. Add some diamonds and other precious stones and this exquisite setting of the past and the present would ace your jewel game and look superb with any outfit.
                                            [4] => Add a pop of colour
                                            [5] => You can also revive up your old jewellery by adding some colored gemstones to it. You can try some rich bold colours that will match the needs of almost all occasions or can even add their zodiac stones with a belief that it will bring immense luck and prosperity to you. While Rubies stand for love and passion, blue sapphires are referred to as the sign of promise, honesty, and loyalty.
                                            [6] => Play with the metals
                                            [7] => Sometimes vintage jewellery may not be in the accurate shape and style as per your desire. Don't throw it away! Visit a creative jewellery designer and get it custom made in any metal of your choice be it gold or silver, with added gemstones to give you a fresh piece.
                                            [8] => Reinvent the old gold!
                                            [9] => An easy way to enhance the old jewel's charm is to get it professionally cleaned and inspected. The seasoned professionals will not just clean and clear all the buffs from the pieces handed over to them but will also revamp the setting of the precious gems if required.
                                            [10] => "If the vintage pieces in one's closet have some precious gemstones but is not accurate for a ring setting, then the jewellery designers can add some elements like metals, diamonds, and more to transform it into beautiful earrings or pendants," said Kunwar Sahib Singh, Director & Creative Head Motiwala & Sons.
                                            [11] => Don't hesitate to experiment
                                            [12] => With layering necklaces, bracelets or even rings of the modern and heirloom styles, you can easily get the affluent boho-chic vibe right. Pritesh Goyal, Designer SLG Jewellers said,"There is no certain rule for mix-and-match themes, just keep the theme of the occasion and the color code of the dress in mind while making the choice of jewels. And, once you have started doing it, you will be amazed by the variety of jewels you have and will start to love all your ancestral jewels all over again."
                                            [13] => So all the women out there, go reinvent the flashback jewels! (ANI)
                                        )

                                )

                        )

                )

        )
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...