Jump to content

Search the Community

Showing results for tags 'php foreach xml'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Having some issues with appending an XML file thru a foreach loop. First some info on the script. The script opens an XML file on my server and reads thru the contents extracting url values. It takes that url value (stored in $urlhtml) and passes to a curl function which in turn curls the url, parse information and passes that thru variable $html back to script. The value of $html is then appended to the XML in a particular location. The initial curl ($urlhtml) is a website with TV shows and the $urlhtml represents a particular show. The $html value represents each episode returned from the curl, which needs to be stored under the show being curled. Following an example of the xml sturcture and below that is the script that does this. What is happening is that the url of the is taken from the XML, the foreach loop is entered, the curl is made and the url for each episode is extracted and appended into the xml, but the problem is that instead of the episode url being appended under respective item element in the xml(where the show is located), all the urls for all episodes are appended under the first item in the XML file. So after executing, if I look at the xml file, all of my shows are under a different item element as needed, but all episode titles and episode urls for all shows are located under one item element, not under it's respective show. Any help or advice in getting episodes under it's show would be greatly appreciated. Thanks <feed> <item> <showname>Name of Show Goes Here</showname> <streamUrl>http://locationofshowstream.com</streamUrl> <episodetitle>Name of Episode Goes Here</episodetitle> <episodeurl>URL of the Episode Goes Here</episodeurl> </item> </feed> $xml = new SimpleXMLElement(file_get_contents($xmllocation)); if (!$xml){ echo 'ERROR WHILE PARSING DOCUMENT'; } else{ foreach($xml->item as $item){ $url=$item->streamUrl; if (!$url){ echo 'ERROR WHILE PARSING'; }else{ $html = file_get_html($url); $xmlappend=simplexml_load_file($xmllocation); $elements=$html->find('a[class=main-tt]'); foreach($elements as $element) { $stitle=$element->title; $streamer=$element->href; $urlhtml=curlurl2($streamer); //CURL EACH $episodeurl=substr($urlhtml,2); //CREATES THE FULL URL PATH $epitem= $xmlappend->item; $episodetitle=$xmlappend->item->addChild('eptitle', $stitle); $episode=$xmlappend->item->addchild('epiurl', $episodeurl); } $xmlappend->asXML($xmlsave); } } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.