simplexml

php simplexml_load_file

一笑奈何 提交于 2019-12-06 15:08:03
问题 I'm new to PHP and this may be a stupid question to ask, so don't vote me down just because I don't understand something... php -r "print_r(simplexml_load_file('http://twitter.com/statuses/user_timeline/31139114.rss'));" let's take this for an example, by running this command i get (on screen) XML output. my question is it possible to save this data instead of just screen but in a file and then read that file and have exact same as if you've have made that simplexml_load_file() 回答1: You can

Get Twitter feed and display information using SimpleXML

孤街浪徒 提交于 2019-12-06 14:17:43
问题 Based on the thread With PHP preg_match_all, get value of href, I'm trying to get some information from a twitter feed. Here is the feed url (for testing purpose): Twitter feed Here is my code: function parse_feed($process) { $xml = @simplexml_load_string($process); $findTweet = $xml['entry']; return $findTweet; } $username = 'tweet'; $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=2"; $feed = file_get_contents($feed); //echo $feed; print_r(parse_feed($feed)); I

Using usort with simplexml

自古美人都是妖i 提交于 2019-12-06 12:54:13
问题 I'm having a problem where none of my values are ending up in the right order. $xml = file_get_contents('admin/people.xml'); $x = new SimpleXMLElement($xml); $sort=$x->person; function cmp($a, $b){ if ($a->age == $b->age) { return 0; } return ($a->age < $b->age) ? -1 : 1; } usort($sort, 'cmp'); foreach ($sort as $key => $value) { echo "$key: $value->age<br>"; } From everything I've read, this should work, but it doesn't. Here is the XML: <people> <person> <name>Frank</name> <age>12</age> <

iterating SimpleXml xpath result

蹲街弑〆低调 提交于 2019-12-06 11:53:22
I'm using SimpleXMLElement to read xml returned from a remote server. The results are then parsed with xpath like this: $result = <<<XML <DataImport2Result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.xxx.xxx/Services/DataImport2"> <Number /> <Blocks> <Block> <Code>Fbf</Code> <Fields> <Field> <Code>FinnsIFbf</Code> <Value>1</Value> </Field> </Fields> </Block> </Blocks> </DataImport2Result> XML; $xml = new SimpleXMLElement($result); $xml->registerXPathNamespace("data", array_pop($xml->getNamespaces())); foreach($xml->xpath(

How to parse an XML node with a colon tag using PHP

风格不统一 提交于 2019-12-06 11:19:32
I am trying to fetch the value of the following nodes from [this URL (takes quite some time to load)][1]. The elements I'm interested in are: title, g:price and g:gtin The XML starts like this: <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <channel> <title>PhotoSpecialist.de</title> <link>http://www.photospecialist.de</link> <description/> <item> <g:id>BEN107C</g:id> <title>Benbo Trekker Mk3 + Kugelkopf + Tasche</title> <description> Benbo Trekker Mk3 + Kugelkopf + Tasche Das Benbo Trekker Mk3 ist eine leichte Variante des beliebten Benbo 1. Sein geringes Gewicht macht das

Get specific node in xml?

只愿长相守 提交于 2019-12-06 11:02:14
my xml is structured as follow: <?xml version="1.0" ?> <users> <user> <name> foo </name> <token> jfhsjfhksdjfhsjkfhksjfsdk </token> <connection> <host> localhost </host> <username> root </username> <dbName> Test </dbName> <dbPass> 123456789 </dbPass> </connection> </user> <user> ... same structure... </user> </users> I made this code that iterate through all xml node: function getConString($node) { $item = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "con"); $nodes = new SimpleXMLElement($item); $result = $nodes[0]; foreach($result as $item => $value) { if($item == "token") { return $value->_

iterating over SimpleXML Objext PHP

﹥>﹥吖頭↗ 提交于 2019-12-06 10:26:22
问题 Here is what my object looks like with print_r (this is an object returned by the PHP SDK for the Amazon Web Services Simple DB. [GetAttributesResult] => CFSimpleXML Object ( [Attribute] => Array ( [0] => CFSimpleXML Object ( [Name] => data_datein [Value] => 2011-04-23 ) [1] => CFSimpleXML Object ( [Name] => data_estatus [Value] => 0 ) [2] => CFSimpleXML Object ( [Name] => data_status [Value] => 1 ) [3] => CFSimpleXML Object ( [Name] => data_title [Value] => Company Info ) [4] => CFSimpleXML

trying to read live rss, but its returning same xml

做~自己de王妃 提交于 2019-12-06 09:55:32
I am trying to read xml file from "http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml" I understand its caching issue so i have added no-cache but stil its returning same file :( <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache"); Header('Pragma: no-cache'); $url = "http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml"; $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER,

SimpleXML: Get value where attribute is variable [duplicate]

做~自己de王妃 提交于 2019-12-06 08:20:29
问题 This question already has answers here : SimpleXML: Selecting Elements Which Have A Certain Attribute Value (2 answers) Closed 6 years ago . <path> <name> <option id="6523"> <needle>Haystack</needle> <foo>bar</foo> </option> <option id="6524"> <needle>Haystack</needle> <foo>Bar</foo> </option> </name> </path> Hello again Stackoverflow! For example, i want the Needle and the foo from option 6524, how do i get those using SimpleXML? I've tried xpath (almoast every topic here on stackoverflow

Add rss xmlns namespace definition to a php simplexml document?

蓝咒 提交于 2019-12-06 05:57:30
I'm trying to create an itunes-valid podcast feed using php5's simplexml: <?php $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <channel> </channel> XML; $xml_generator = new SimpleXMLElement($xml_string); $tnsoundfile = $xml_generator->addChild('title', 'Main Title'); $tnsoundfile->addChild('itunes:author', "Author", ' '); $tnsoundfile->addChild('category', 'Audio Podcasts'); $tnsoundfile = $xml_generator->addChild('item'); $tnsoundfile->addChild('title', 'The track title'); $enclosure = $tnsoundfile->addChild('enclosure'); $enclosure->addAttribute('url', 'http://test.com');