Jump to content

Search the Community

Showing results for tags 'simplexml'.

  • 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 9 results

  1. Hello... I want to calculate the value from 2 difference files using simplexml load file... But the result not as expected.. My output should be 7 and 5 where 10 - 7 and 8 - 3. My first xml files. <?xml version="1.0" encoding="UTF-8"?> <items> <item> <q_id>4131001</q_id> <value>10</value> </item> <item> <q_id>4232002</q_id> <value>8</value> </item> </items> My second xml files. <?xml version="1.0" encoding="UTF-8"?> <items> <item> <q_id>4131001</q_id> <value>7</value> </item> <item> <q_id>4232002</q_id> <value>3</value> </item> </items> My scripts. <?php $xml = simplexml_load_file('q1.xml'); $xml2 = simplexml_load_file('q2.xml'); foreach ($xml -> item as $item) { $value1 = $item->value; echo $item->q_id.'<br />'; //echo $value1.'<br />'; foreach ($xml2 -> item as $item2) { $value2 = $item2->value; $total = $value1 - $value2; echo $total.'<br />'; } } ?> The result should be 7 and 5 where 10 - 7 and 8 - 3 but there is another unknows value which is 3 and 1... How to solve the issue.. Thank for any help..
  2. Hey guys, Sorry, php noob here, but can grasp new concepts rather quickly. I've been in IT a long time and this is my first time trying to rewrite this much php code. I've been working on this php script for 7 days now and think I'm getting close. I've seen most every syntax error, have learned a lot and morphed the code into what it is now. The script I'm hacking was written back in 09 with 16 (static) user data fields in an array to test register a user at a third-party website via SSL with curl and a simple xml load string. If you get a success response, all went well with the other server. If not, all you get is a fail response. The first 6 data fields will still remain static, but the last 10 will always vary because I'm querying a WP user DB to get user data. The script just queries the WP user DB creates an array and posts to the other server and registers the user, so the user that registered with the first site doesn't have to go through the whole registration process over again. This is totally G-rated. It's for a consumer discounts site. Here's what I'm trying to get the code to do. Create an array, query the DB and then pass the first static array data and the user array data to the post string and get a success response from the other server. This is the whole script that's failing and I'm only able to see, Status: fail. Nice error code huh? Here's my code: error_reporting(E_ALL); ini_set('display_errors',true); // Set the Query POST parameters $query_vals = array( 'api_username' => 'api-name-here', 'api_password' => 'api-password', 'api_key' => 'key-goes-here', 'perkalert' => 0, 'offer_radius' => 20, 'send_welcome_email' => 1 ); // Call WordPress function wp_get_current_user_info() //Create array function wp_get_current_user_info() { $current_user = wp_get_current_user(); $current_user-> $value; $n="user_variable_{$type}_name"; ${$n} = true; $current_user_info = array( 'firstname' . $current_user->user_firstname =>'n', 'lastname' . $current_user->user_lastname =>'n', 'address' . $current_user->mepr-address-one =>'n', 'city' . $current_user->mepr-address-city =>'n', 'state' . $current_user->mepr-address-state =>'n', 'zip' . $current_user->mepr-address-zip =>'n', 'country' . $current_user->mepr-address-country =>'n', 'email' . $current_user->user_email =>'n', 'username' . $current_user->user_login =>'n', 'password' . $current_user->user_pass =>'n' ); return $current_user_info; } $postdata = ''; $key = '='; $value = '&' $query_vals = array(); $current_user_info = array(); $result = array_merge($query_vals, $current_user_info); { foreach($query_vals as $key => $value); foreach($current_user_info as $key => $value); $postdata .= $key.'='.urlencode($value).'&'; } // Chop of the trailing ampersand $postdata = rtrim($postdata, '&'); // create a new cURL resource $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://secureserver/client/register_member.xml'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); // Save response to a string $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); //var_dump($xml); echo "Status: ".$xml->status; Any help is really appreciated. Thanks.
  3. Hi I've searched the net high and low for an answer and found a script on this forum which I have used as shown below however the script seems to run fine and output to the screen with the correct data, however it doesn't update the database on the server. I've checked permissions and ran a simple query static query which works: (mysqli_query($con,"INSERT INTO feeforeviews (FEEDBACKID,COUNT,DATE) VALUES ('99999,10,3 Hour(s) ago')") and it updates the "feeforeviews" table fine. This is the script I would like working if possible which parses the file feefofeedtest.xml and should import the data in the database table "feeforeviews" I modified the script from here: http://forums.phpfreaks.com/topic/273301-simplexml-to-mysql/ http://forums.phpfreaks.com/user/3105-barand/ Any help greatly appreciated. <?php // Create connection $con=mysqli_connect("localhost","user","pass","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> <?php $xml = simplexml_load_file('feefofeedtest.xml'); $data = $fields = array(); foreach ($xml->xpath('FEEDBACK') as $FEEDBACK) { $fields = array_keys((array)($FEEDBACK)); $data[] = '(' . join(', ', (array)$FEEDBACK) . ')'; } $sql = "INSERT INTO feeforeviews (" . join(', ', $fields) . ") VALUES\n" ; $sql .= join (",\n", $data); echo "<pre>$sql</pre>"; ?> This outputs the following onscreen which looks fine, however it doesn't update the server. INSERT INTO feeforeviews (FEEDBACKID, COUNT, DATE, HREVIEWDATE, DESCRIPTION, PRODUCTCODE, LINK, FACEBOOKSHARELINK, PRODUCTRATING, SERVICERATING, CUSTOMERCOMMENT, SHORTCUSTOMERCOMMENT, READMOREURL) VALUES (99998, 1, 3 Hour(s) ago, 2014-03-18T10:19:03, Personalised Swarovski Crystal Hiball Glass, DG10387, http://www.keepitpersonal.co.uk, http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.feefo.com%2FGB%2Fen%2Freviews%2FKeep-It-Personal%2F%3Fid%3D326784%26servicefeedbackid%3D83637, 5, ++, ++, jgsjhgdfhjgjsd, Service rating : jgsjhgdfhjgjsd, http://www.feefo.com/GB/en/reviews/Keep-It-Personal/?id=326784&servicefeedbackid=83637), (88888, 2, 5 Hour(s) ago, 2014-03-18T08:02:34, Personalised Swarovski Champagne Flute, DG10492, http://www.keepitpersonal.co.uk, http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.feefo.com%2FGB%2Fen%2Freviews%2FKeep-It-Personal%2F%3Fid%3D326784%26servicefeedbackid%3D86279, NA, ++, Excellent website, easy to understand and use, jgsjhgdfhjgjsd, http://www.feefo.com/GB/en/reviews/Keep-It-Personal/?id=326784&servicefeedbackid=86279) Example XML file: <?xml version="1.0" encoding="UTF-8"?><FEEDBACKLIST> <FEEDBACK> <FEEDBACKID>99998</FEEDBACKID> <COUNT>1</COUNT> <DATE> 3 Hour(s) ago</DATE> <HREVIEWDATE>2014-03-18T10:19:03</HREVIEWDATE> <DESCRIPTION>Personalised Swarovski Crystal Hiball Glass</DESCRIPTION> <PRODUCTCODE>DG10387</PRODUCTCODE> <LINK>http://www.keepitpersonal.co.uk</LINK> <FACEBOOKSHARELINK>http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.feefo.com%2FGB%2Fen%2Freviews%2FKeep-It-Personal%2F%3Fid%3D326784%26servicefeedbackid%3D83637</FACEBOOKSHARELINK> <HREVIEWRATING>5</HREVIEWRATING> <PRODUCTRATING>++</PRODUCTRATING> <SERVICERATING>++</SERVICERATING> <CUSTOMERCOMMENT>jgsjhgdfhjgjsd</CUSTOMERCOMMENT> <SHORTCUSTOMERCOMMENT>Service rating : jgsjhgdfhjgjsd</SHORTCUSTOMERCOMMENT> <READMOREURL>http://www.feefo.com/GB/en/reviews/Keep-It-Personal/?id=326784&servicefeedbackid=83637</READMOREURL> </FEEDBACK> <FEEDBACK> <FEEDBACKID>88888</FEEDBACKID> <COUNT>2</COUNT> <DATE> 5 Hour(s) ago</DATE> <HREVIEWDATE>2014-03-18T08:02:34</HREVIEWDATE> <DESCRIPTION>Personalised Swarovski Champagne Flute</DESCRIPTION> <PRODUCTCODE>DG10492</PRODUCTCODE> <LINK>http://www.keepitpersonal.co.uk</LINK> <FACEBOOKSHARELINK>http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.feefo.com%2FGB%2Fen%2Freviews%2FKeep-It-Personal%2F%3Fid%3D326784%26servicefeedbackid%3D86279</FACEBOOKSHARELINK> <PRODUCTRATING>NA</PRODUCTRATING> <SERVICERATING>++</SERVICERATING> <CUSTOMERCOMMENT>Excellent website, easy to understand and use</CUSTOMERCOMMENT> <SHORTCUSTOMERCOMMENT>jgsjhgdfhjgjsd</SHORTCUSTOMERCOMMENT> <READMOREURL>http://www.feefo.com/GB/en/reviews/Keep-It-Personal/?id=326784&servicefeedbackid=86279</READMOREURL> </FEEDBACK></FEEDBACKLIST>
  4. I am trying to get the names of the children nodes in XML Here is the code: foreach ($pos->children() as $child) { echo "I never get here"; echo $child->getName() . "\n"; } //} echo "but the node has children---<br>"; print_r($pos); which I modeled on the code from http://www.php.net/manual/en/simplexmlelement.getname.php and here is a sample of the output: SimpleXMLElement Object ( [n] => SimpleXMLElement Object ( ) ) but the node has children--- SimpleXMLElement Object ( [int] => SimpleXMLElement Object ( ) ) but the node has children--- SimpleXMLElement Object ( [n] => SimpleXMLElement Object ( ) ) Why can't I go through the chldren with foreach?
  5. I am trying to create a flickr url using the XML file from the site the code I am using is as follows <?php $file="http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=7952c4f1e6dfd2ae1420aec860616f6e&user_id=93306691%40N08&format=rest&auth_token=72157636755071086-2072507680111a83&api_sig=8032afd164bff4d17c4574ae246ce92b"; $sets=simplexml_load_file($file); foreach($sets->xpath('//photoset') as $set){ echo '<a><li><img src="http://farm'.$set{farm-id}.'.staticflickr.com/'.$set{server-id}.'/'.$set{id}.'_'.$set{secret}.'.jpg"/><h3>'.$set->title.'</h3></li></a>'; } //print_r($sets); ?> The XML is laid out as below <photosets cancreate="1" page="1" pages="1" perpage="13" total="13"> <photoset id="72157634817057978" primary="9378217918" secret="66a440b8e3" server="3753" farm="4" photos="28" videos="0" needs_interstitial="0" visibility_can_see_set="1" count_views="34" count_comments="0" can_comment="1" date_create="1374935118" date_update="1374954932"> <title>Coventry v Birmingham - 26-07-13</title> <description>Photos of the occasion when the Birmingham Brummies ascended to the top of the Elite League table.</description> </photoset> </photosets> But I am getting the following error displayed Notice: Use of undefined constant farm - assumed 'farm' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant server - assumed 'server' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant secret - assumed 'secret' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6The parameters I need are within the photoset tag and not tags on their own. Any help would be great
  6. I've got some code that displays a feed from a wordpress xml and it does perfectly on my mamp localhost but when I put it on the windows server everthing just falls apart. <?php $curl = curl_init(); curl_setopt_array($curl, Array( CURLOPT_URL => 'http://blog.thisisfusion.com/feed/', CURLOPT_USERAGENT => 'spider', CURLOPT_TIMEOUT => 120, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_ENCODING => 'UTF-8' )); $data = curl_exec($curl); curl_close($curl); $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); ?> And the loop portion here: <?php $i = 0; foreach ($xml->channel->item as $item) { $creator = $item->children('dc', TRUE); echo '<h2>' . $item->title . '</h2>'; echo '<small>Posted on '. date('l F d, Y', strtotime($item->pubDate)) .' by '.$creator.'</small> </p>'; echo '<p class="description">' . $item->description . '</p>'; if (++$i > 2) break; } ?> It's having a fit on the server saying that THIS section foreach ($xml->channel->item as $item) is trying to get the property of a nonobject and that it's an invalid argument in foreach. If this was truly the case, why is it working on my localhost? I've tried a lot of different methods and I have no clue what to do anymore. I var_dumped and didn't see anything maybe something in $xml is null and I missed it? But I checked to make sure that wasn't the case. I don't know. I would appreciate some help. Thank you.
  7. I am working on keeping track of page views. Unfortunately, I can't do this with a database. I need to keep track of this in an XML file. The XML file contents are only available through web services, which I read and edit using a Soap Client. In the end, each page on teh website will have this block of code. The block of code automatically updates itself to contain a unique ID for each page. So when the code runs, each page will run it using a different ID. If check if the page already exists in the XML file and process either updating the number of views or adding it to the XML. The later works just fine. I cannot seem to update the XML structure and pass it back. Any help is very much welcome. XML structure: <pages> <page> <id>o8427fho84uhfir</id> <views>1</views> </page> </pages> Relevant code: <?php define('PAGE_ID', 'UNIQUE_ID'); $readResponse = $client->read($readRequest); if ( $readResponse->readReturn->success == 'true' ) { $asset = (array) $readResponse->readReturn->asset->xmlBlock; $xml = new SimpleXMLElement($asset['xml']); // Check if current page already exists $page = $xml->xpath("page[id='".PAGE_ID."']"); if ( $page ) { // Cannot get this part to work $page[1] += 1; $xml->asXml(); } else { // This section works well $page = $xml->addChild('page'); $page->addChild('id',PAGE_ID); $page->addChild('views',1); $asset['xml'] = $xml->asXML(); } // Edit block $editResponse = $client->edit($editRequest); } ?>
  8. First, thanks in advance for any help. Here's my issue. I've read through tons of similar problems here but I don't think I'm understanding this enough to make this work. I have an XML file such as: <unitlist> <unit> <iterator>0</iterator> <route>2</route> <rt_name>'Riverfront Streetcar'</rt_name> <name>457</name> <lat>2956.21014</lat> <lng>-9004.62839</lng> <bearing>2.14501</bearing> <car_type>'RTA Street Cars'</car_type> <speed>16.57122</speed> <GMT>043432</GMT>[/indent] </unit> <unit> <iterator>1</iterator> <route>10</route> <rt_name>'Tchoupitoulas'</rt_name> <name>250</name> <lat>2958.0927</lat> <lng>-9005.28724</lng> <bearing>1.532399</bearing> <car_type>'RTA Buses'</car_type> <speed>0.6904677</speed> <GMT>104620</GMT>[/indent] </unit> </unitlist> What I want to do is, for each <unit>, import all attributes of that unit (iterator,route,rt_name, etc, etc, etc) into my mySQL database. My problem is that, all it's doing is importing the same attributes of the first <unit> the number of times that <unit> exists. In this example, it's importing the same information from the first <unit> twice, as two records/rows. If I had 90 <unit>s, it would import 90 identical records. Here's my code: foreach($unitlist->unit as $unit) { //insert into database mysql_query("INSERT INTO businfo (iterator,route,rt_name,name,lat,lng,bearing,car_type,speed,GMT)VALUES (\"$iterator\",\"$route\", \"$rt_name\", \"$name\", \"$lat\", \"$lng\", \"$bearing\", \"$car_type\", \"$speed\", \"$GMT\")") or die(mysql_error()); } Can anyone explain what I'm doing wrong? Thanks again for the help! - dan -
  9. cmb

    Simplexml

    In searching how to wright cdata tags into my xml document using simpleXML i came across this example and when i try and use it Dreamweaver shows that lines 4-7 are wrong i try and run the code anyway and i get this error syntax error, unexpected T_VARIABLE on line 4 <?php class SimpleXMLExtended extends SimpleXMLElement{ public function addCData($cdata_text){ $node= dom_import_simplexml($this); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($cdata_text)); } } $xml_doc = new SimpleXMLExtended('save.xml',NULL,TRUE); $email = $xml_doc->addChild('email'); $email->addAttribute('id',$id); $email->from = NULL; $email->from->addCData($from); $xml_doc->asXML('save.xml'); ?>
×
×
  • 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.