I'm working on storing result of xml feed into database... I'm able to load file... but when I want to store data into array, it stores instead of value ([title] = 'Klapka 120mm';) this:      [title] => SimpleXMLElement Object ( [0] => Klapka 120mm )   Do you know, where might be problem?  Source code:   Here is part of one function:  $import_file = simplexml_load_file($this-&gt;input-&gt;post('import_url')); // load file from url $affected_products = 0;      foreach($import_file-&gt;SHOPITEM as $product) {                     $affected_products += $this-&gt;import_product($product);     }      Here is first part of function import_product:  public function import_product($product)  {        /* save product data into array */    $data = array(             'title' =&gt; $product-&gt;PRODUCT,             'content' =&gt; $product-&gt;DESCRIPTION,             'price' =&gt; $product-&gt;PRICE,             'price_vat' =&gt; $product-&gt;PRICE_VAT,             'ean' =&gt; $product-&gt;EAN,             'count' =&gt; $product-&gt;AVAILABILITY         );    die(print_r($data));   Thank you very much for your replies
4477
Let's say I have some XML like this  &lt;channel&gt;   &lt;item&gt;     &lt;title&gt;This is title 1&lt;/title&gt;   &lt;/item&gt; &lt;/channel&gt;   The code below does what I want in that it outputs the title as a string  $xml = simplexml_load_string($xmlstring); echo $xml-&gt;channel-&gt;item-&gt;title;   Here's my problem.  The code below doesn't treat the title as a string in that context so I end up with a SimpleXML object in the array instead of a string.  $foo = array( $xml-&gt;channel-&gt;item-&gt;title );   I've been working around it like this  $foo = array( sprintf("%s",$xml-&gt;channel-&gt;item-&gt;title) );   but that seems ugly.  What's the best way to force a SimpleXML object to a string, regardless of context?
114402
I'm trying to load a field value (machine name: field_theme_image) from a content of node value 3, in "page--front.tpl.php".  &lt;?php   $node=node_load(3);   print $node-&gt;field_theme_image[$node-&gt;language][0]['uri']; ?&gt;   Using the above code I'm not getting full URL value. Please see the image below. I can see the path value in Devel themer.
3156
Here are the args for my query :  $args = array(     'post_type' =&gt; 'news',     'meta_query' =&gt; array(         array(             'key' =&gt; 'topics',             'value' =&gt; 'sports',         )     ) );   This works when topics is a string, but not when it is an array. I'd like this query to work when topics is for example array( 'sports', 'nonprofit', etc. )  Is there a way to build meta queries with arrays as a meta_key ?
61794
I have a Partner sending some data to a Triggered Email/Data Extension which includes a column for XML data.   The trigger is erroring and not allowing the data to get to the Data Extension.   Below is what they are sending over. Is the formatting of the XML incorrect?  XML data that I've used in the past in Data Extensions starts with....   &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;   This version of XML starts with... {"XML":  Could that be it?  {"To": {"SubscriberKey": "test@acme.com", "ContactAttributes": {"SubscriberAttributes": **{"XML":** "&lt;root&gt;&lt;ITEM&gt;&lt;ITEM_PRODUCT_NAME&gt;dark chocolate nuts &amp; sea salt&lt;/ITEM_PRODUCT_NAME&gt;&lt;ITEM_PRODUCT_SKU&gt;15127&lt;/ITEM_PRODUCT_SKU&gt;&lt;ITEM_PRODUCT_URL&gt;https://www.test.com/15127.html&lt;/ITEM_PRODUCT_URL&gt;&lt;ITEM_PRODUCT_IMG_URL&gt;https://www.test.com/images/nuts.png&lt;/ITEM_PRODUCT_IMG_URL&gt;&lt;ITEM_QTY&gt;1&lt;/ITEM_QTY&gt;&lt;ITEM_SUBSCRIPTION_PRICE&gt;12.59&lt;/ITEM_SUBSCRIPTION_PRICE&gt;&lt;ITEM_TOTAL&gt;12.59&lt;/ITEM_TOTAL&gt;&lt;/ITEM&gt;&lt;ITEM&gt;&lt;ITEM_PRODUCT_NAME&gt;crunchy peanut butter&lt;/ITEM_PRODUCT_NAME&gt;&lt;ITEM_PRODUCT_SKU&gt;41800&lt;/ITEM_PRODUCT_SKU&gt;&lt;ITEM_PRODUCT_URL&gt;https://www.test.com/images/butter.png&lt;/ITEM_PRODUCT_IMG_URL&gt;&lt;ITEM_QTY&gt;1&lt;/ITEM_QTY&gt;&lt;ITEM_SUBSCRIPTION_PRICE&gt;11.37&lt;/ITEM_SUBSCRIPTION_PRICE&gt;&lt;ITEM_TOTAL&gt;9.55&lt;/ITEM_TOTAL&gt;&lt;/ITEM&gt;&lt;ITEM&gt;&lt;ITEM_PRODUCT_NAME&gt;pear cinnamon &amp; pecan&lt;/ITEM_PRODUCT_NAME&gt;&lt;ITEM_PRODUCT_SKU&gt;17227&lt;/ITEM_PRODUCT_SKU&gt;&lt;ITEM_PRODUCT_URL&gt;https://www.test.com&lt;/ITEM_PRODUCT_URL&gt;&lt;ITEM_PRODUCT_IMG_URL&gt;https://www.test.com/images/apples.png&lt;/ITEM_PRODUCT_IMG_URL&gt;&lt;ITEM_QTY&gt;1&lt;/ITEM_QTY&gt;&lt;ITEM_SUBSCRIPTION_PRICE&gt;12.59&lt;/ITEM_SUBSCRIPTION_PRICE&gt;&lt;ITEM_TOTAL&gt;12.59&lt;/ITEM_TOTAL&gt;&lt;/ITEM&gt;&lt;/root&gt;", "SHIPPING_LNAME": "Tester", "FIRST_NAME": "Test", "LAST_NAME": "Tester", "ORDER_TOTAL_SAVINGS": -5.97, "MERCHANT_ORDER_ID": "1810002352", "SHIPPING_ADDRESS_STATE": "NY", "ORDER_PLACE_DATE_LONG": "Fri 11 January 2019", "SHIPPING_ADDRESS_ZIP": "10004", "ORDER_SHIPPING": 0.00, "CARD_TYPE": "Visa", "ORDER_SUBTOTAL": 47.32, "ORDER_PLACE_DATE_SHORT": "01/11/2019", "SHIPPING_FNAME": "Test", "SHIPPING_ADDRESS_TOWN": "new york", "ORDER_TOTAL": 47.32, "CARD_EXPIRE": "12/2027", "CARD_HOLDER": "Test Tester", "SHIPPING_ADDRESS_1": "75 broad st", "SHIPPING_ADDRESS_2": "fl 23"}}, "Address": "acme@test.com"}}   AMPSCRIPT IN EMAIL Calling the XML....  %%[   var @LOOPINGAPPENDIX  set @LOOPINGAPPENDIX = AttributeValue("LOOPINGAPPENDIX")  set @productRows = BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM", 0)  ]%%   %%[   for @j = 1 to RowCount(@productRows) do       set @productXML = Concat("", Field(Row(@productRows, @j), "XML"), "")      set @ITEMPRODUCTNAME = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_PRODUCT_NAME", 0), 1), "Value"))      set @ITEMPRODUCTSKU = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_PRODUCT_SKU", 0), 1), "Value"))      set @ITEMPRODUCTURL = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_PRODUCT_URL", 0), 1), "Value"))      set @ITEMPRODUCTIMGURL = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_PRODUCT_IMG_URL", 0), 1), "Value"))      set @ITEMQTY = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_QTY", 0), 1), "Value"))      set @ITEMSUBSCRIPTIONPRICE = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_SUBSCRIPTION_PRICE", 0), 1), "Value"))      set @ITEMTOTAL = Trim(Field(Row(BuildRowSetFromXML(@LOOPINGAPPENDIX, "/root/ITEM/ITEM_TOTAL", 0), 1), "Value"))      set @rowColor = Iif(Mod(@j,2) == 0, "#efefef", "#ffffff")   ]%%   %%[endif]%%   %%[next @j]%%
92236
I have an xml file which I would like to create a form/table around to add, edit and delete records using PHP.  Currently I use simpleXML to load the XML file, and display its content on various pages.  Is there any way I can create a table that shows all results, and allows me to either edit or delete that particular row of the table which represents a full record within the XML file.    When clicking edit I would like the details from the record to appear in a form which the user can change and then save out, updating the XML file and the corresponding web page.  I need this done in PHP, preferably using SimpleXML, though open to suggestions of other ways to do this with PHP.  Cheers
121031
I have a the following code:  // Create an Entity with wrapper   $node = entity_create('node', array('type' =&gt; 'person'));   $entity = entity_metadata_wrapper('node',  $node);    // Add a node title   $entity-&gt;title = $person['name'];    // Add the address information   $entity-&gt;field_person_address-&gt;thoroughfare = $person['address'];   $entity-&gt;field_person_address-&gt;locality = $person['city'];   $entity-&gt;field_person_address-&gt;administrative_area = $person['state'];   $entity-&gt;field_person_address-&gt;postal_code = $person['postalcode'];   $entity-&gt;field_person_address-&gt;country = $person['country'];    // Save the entity   $entity-&gt;save();   The data is saved in the DB perfeclty, but I need to get the entity ID of the new save node.   How do I do that?
26577
I have a bunch of client point of sale (POS) systems that periodically send new sales data to one centralized database, which stores the data into one big database for report generation.  The client POS is based on PHPPOS, and I have implemented a module that uses the standard XML-RPC library to send sales data to the service. The server system is built on CodeIgniter, and uses the XML-RPC and XML-RPCS libraries for the webservice component. Whenever I send a lot of sales data (as little as 50 rows from the sales table, and individual rows from sales_items pertaining to each item within the sale) I get the following error:  Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 54 bytes)   128M is the default value in php.ini, but I assume that is a huge number to break. In fact, I have even tried setting this value to 1024M, and all it does is take a longer time to error out.  As for steps I've taken, I've tried disabling all processing on the server-side, and have rigged it to return a canned response regardless of the input. However, I believe the problem lies in the actual sending of the data. I've even tried disabling the maximum script execution time for PHP, and it still errors out.
81707
We are migrating over to Lightning Web Components in the last couple of weeks now and we had some struggles with the arrays in Javascript. On a trackable array, when I call push in a wiredMethod, Array.push won't update the view. We found a workaround but I was wondering if there is a more elegant solution to this. Please take a look at the code snippets:  import { LightningElement, wire, track } from 'lwc'; import getData from '@salesforce/apex/LWCController.getData';  export default class myLWComponent extends LightningElement {     @track error;     @track dataArray = [];     @track processedArray = [];      @wire(getData)     wiredMethod({ error, data }) {         if (data) {             this.dataArray = data.arr;             this.dataArray.forEach(function (value) {                 // do some work on data here                 this.processedArray.push(value);             }         } else if (error) {             this.error = error;         }     }                  }   And on the view here:  &lt;lightning-card title="Card Title"&gt;     &lt;template for:each={processedArray} for:item='item'&gt;         {item.title}     &lt;/template&gt; &lt;/lightning-card&gt;   Here is our workaround:  export default class myLWComponent extends LightningElement {     @track error;     @track dataArray = [];     @track processedArray = [];      @wire(getData)     wiredMethod({ error, data }) {         if (data) {             this.dataArray = data.arr;             let tempArray = [];             this.dataArray.forEach(function (value) {                 // do some work on data here                 this.tempArray.push(value);             }             this.processedArray = tempArray;         } else if (error) {             this.error = error;         }     }                  }   As you can see from the work around, if we set array to the temp array, framework understands that the array is updated and updates the view accordingly. We also tried setting values as follows which didn't work:  this.processedArray[index] = value;   We are wondering why push doesn't work and/or if there is a better way to do this.
43371
PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the empty() function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?
44995
I had this question earlier and it was concluded it was a bug in 5.2.5.  Well, it's still broken in 5.2.6, at least for me:  Please let me know if it is broken or works for you:  $obj = new stdClass(); $obj-&gt;{"foo"} = "bar"; $obj-&gt;{"0"} = "zero"; $arr = (array)$obj;  //foo -- bar //0 --    {error: undefined index} foreach ($arr as $key=&gt;$value){     echo "$key -- " . $arr[$key] . "\n"; }   Any ways to "fix" the array after it has been cast from a stdClass?
86387
Trying to find an XML file I can use in lieu of a look-up database table until we get our web hosting switched over to the right DB.  Can anyone refer me to an XML file with elements whose children have zipcodes, states, and cities? E.g.:  &lt;zip code="98117"&gt;     &lt;state&gt;WA&lt;/state&gt;     &lt;city&gt;Seattle&lt;/state&gt; &lt;/zip&gt;   Or  &lt;entry&gt;     &lt;zip&gt;98117&lt;/zip&gt;     &lt;state&gt;WA&lt;/state&gt;     &lt;city&gt;Seattle&lt;/city&gt; &lt;/entry&gt;   I'll be using LINQ in C# to query this data.
91060
When I do hexdump filename.txt I get the following as output:  00000000 ac5a 5afb c08d 5d15 26d0 2491 e8c9 8917 00000010    When I do &lt;?= bin2hex(file_get_contents('filename.txt')); ?&gt; I get this:  5aacfb5a8dc0155dd0269124c9e81789   So why is hexdump suggesting the contents should be ac5a5afbc08d5d1526d02491e8c98917 when PHP is suggesting they ought to be 5aacfb5a8dc0155dd0269124c9e81789? Am I just not interpreting the output of hexdump correctly?
24215
I have CSV data loaded into a multidimensional array. In this way each "row" is a record and each "column" contains the same type of data.  I am using the function below to load my CSV file.  function f_parse_csv($file, $longest, $delimiter) {   $mdarray = array();   $file    = fopen($file, "r");   while ($line = fgetcsv($file, $longest, $delimiter))   {     array_push($mdarray, $line);   }   fclose($file);   return $mdarray; }   I need to be able to specify a column to sort so that it rearranges the rows.  One of the columns contains date information in the format of Y-m-d H:i:s and I would like to be able to sort with the most recent date being the first row.
33533
I have this as xml:  &lt;root xmlns:event="http://www.webex.com/schemas/2002/06/service/event"&gt;     &lt;event:event&gt;         &lt;event:sessionKey&gt;&lt;/event:sessionKey&gt;         &lt;event:sessionName&gt;Learn QB in Minutes&lt;/event:sessionName&gt;         &lt;event:sessionType&gt;9&lt;/event:sessionType&gt;         &lt;event:hostWebExID&gt;&lt;/event:hostWebExID&gt;         &lt;event:startDate&gt;02/12/2009&lt;/event:startDate&gt;         &lt;event:endDate&gt;02/12/2009&lt;/event:endDate&gt;         &lt;event:timeZoneID&gt;11&lt;/event:timeZoneID&gt;         &lt;event:duration&gt;30&lt;/event:duration&gt;         &lt;event:description&gt;&lt;/event:description&gt;         &lt;event:status&gt;NOT_INPROGRESS&lt;/event:status&gt;         &lt;event:panelists&gt;&lt;/event:panelists&gt;         &lt;event:listStatus&gt;PUBLIC&lt;/event:listStatus&gt;     &lt;/event:event&gt;     ... &lt;/root&gt;   How can I loop through all of the event:event nodes and display, for example, all of the event:SessionKey's?   This does not work:  $xml = new SimpleXMLElement($r); $xml-&gt;registerXPathNamespace('e', 'http://www.webex.com/schemas/2002/06/service/event');  foreach($xml-&gt;xpath('//e:event') as $event) {  var_export($event-&gt;xpath('//e:sessionKey')); }
71838
I created file node--my_content_type.tpl.php, where I'd like to print the username as string. I tried the following code, but unfortunately it doesn't work. How can I do it?  &lt;?php    print $name; ?&gt;
48996
I'd like to implement a simple AJAX function locally that allows me to autocomplete node titles of already existing nodes as the user types. To that end, I need the ability to have an API that I can search on node titles. The problem is that when I output raw JSON, it comes surrounded by tags. So, no matter what I do, I keep getting...  &lt;html&gt;     &lt;head&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;pre style="word-wrap: break-word; white-space: pre-wrap;"&gt; {json here}&lt;/pre&gt;     &lt;/body&gt; &lt;/html&gt;   I've tried implementing a custom page template that only outputs content already, that produced the same results. Here is how I am currently doing this, in my module file...  &lt;?php  /**  * Implementation of hook_menu()  */ function content_relation_menu() {     $items = array();     $items['api'] = array(         'title' =&gt; 'Search',         'page callback' =&gt; 'content_relation_get',         'access callback' =&gt; TRUE,         'type' =&gt; MENU_CALLBACK,     );      return $items; }  function content_relation_get($term = '') {     drupal_add_http_header('Content-Type', 'application/javascript; utf-8');     $var = json_encode(         db_query("SELECT nid,title FROM {node} WHERE title LIKE :title LIMIT 5", array(":title" =&gt; $term.'%'))-&gt;fetchAll()     );     echo $var;     exit(0); }   How can I return JUST raw JSON?
113295
I am trying the contents of an array into a file with each element of the array in a new line in the file.  IFS=$'\n'    echo "${mtches[@]}" &gt; sample1.txt     The content of mtches is "qwe" and " asd". But the sample1.txt file contains qwe asd in a single line. Why is it not taking IFS value into the picture?