Jump to content

blinks

Members
  • Posts

    53
  • Joined

  • Last visited

    Never

Everything posted by blinks

  1. Can anyone explain why this bit of code works - header("Location: http://localhost/workflow/new.php?cat=select_workflow"); but this doesn't - $url = "http://localhost/workflow/new.php?cat=select_workflow" header("Location: $url"); nor does header('Location: '.$url); TIA
  2. Hi salathe, you are right in supposing I want to change the affiliation for all name nodes having an @id greater than zero. And yes, this code does do what I want. There is a foreach loop before the code, which I didn't include. There is only ever one affiliation per name, and as the code is for a one-off global update, it doesn't have to cater for future possibilities. Thanks for your reply :-)
  3. Got it figured out - $fieldNodeList = $xpath->query("/name"); $fieldNodeList2 = $xpath->query("/name/affiliation"); $newString = "hello"; foreach($fieldNodeList as $node) { if ($node->getAttribute("ID") > "0") { $fieldNodeList2->item(0)->nodeValue = $newString; } }
  4. The following code is throwing up a "Cannot use object of type DOMElement as array" error on the $node[@ID >0] line $fieldNodeList = $xpath->query("/name"); $fieldNodeList2 = $xpath->query("/name/affiliation"); $newString = "hello"; foreach($fieldNodeList as $node) { if ($node[@ID > 0]) { $fieldNodeList2->nodeValue = $newString; } } What this is meant to do is change /name/affiliation if the attribute value of /name is greater than 0. Any suggestions, please??
  5. Got it, thank you! Just dropped the ampersand in front of the first $node, as per - $fieldNodeList = $xpath->query("/subject/topic"); foreach($filedNodeList as $node) { if (preg_match('/^keyword2/', $node->nodeValue)) { $node->nodeValue = "key word 2"; } }
  6. Thanks for your reply. Have set the code as per your specs, but it is not throwing up the following error - Fatal error: An iterator cannot be used with foreach by reference in
  7. The following code works nicely if there is one topic node, but not if there are multiple nodes. I know I need a foreach loop. Can anyone help? $fieldNodeList = $xpath->query("/subject/topic"); $currentString = $fieldNodeList->item(0)->nodeValue; if (preg_match('/^keyword2/', $currentString)) { $newString = "key word 2"; $fieldNodeList->item(0)->nodeValue = $newString; } TIA
  8. Thanks heaps! This works beautifully!
  9. I've the following line - $rsd_pids=$parsed_xml['PIDs']['pid']; which reads the content of the <pid> tag of an XML file. Sometimes there may be one <pid> tag, and sometimes more. My code works fine - creates an array - if there is more than one PID tag. $rsd_pids becomes a string if there is just one <pid>. How do I force it to read a single value as an array, not a string? TIA
  10. Problem solved! Although I'm still quite puzzled about one aspect of it - print_r of $pids and $pidlist was showing up the duplicated value in both arrays. The var_dump revealed it was present in one, and missing in the other. Perhaps I put the print_r in a difference location??? Anyway, all good now. I traced the issue back to a bug in the parent program. Thanks for your help.
  11. Sorry, I didn't explain myself very clearly. I do get a lengthy output from array_diff. The issue is that there is one particular array value from among the thousands in each array (it's an integer array) that occurs in both $pid and $pidlist, and therefore shouldn't be in $diff, but is.
  12. I'm using the following bit of code $diff = array_diff($pids, $pidlist); $diff = array_values($diff); //reindex array to remove empties //output to $discrepancy print_r($diff); exit; Both $pids and $pidlist contain exactly the same value; so I would have expected that value not to appear in $diff - but it is. Both $pids and $pidlist contain a few thousand values, and I've only found this one example which appears in both lists as well as $diff. Can anybody shed any light?
  13. Your code does work, KrisNZ! I was using an intermediate file to run the code, and it was pointing to a different server, hence running the "old" code not the new. Thanks heaps!
  14. Thanks for your help, KrisNZ. However, no matter how I incorporate your code into mine, I'm still receiving exactly the same, unformatted output. Obviously I'm doing something wrong, but I can't see what.
  15. The following code outputs a display in Firefox that all runs together on one line, although it formats nicely in IE (indents, coding, +/- etc). Is there a quick and easy way to tweak the code to ensure it also formats in Firefox (i.e. output carriage returns after each tag)? $xmloutput = "<?xml version = \"1.0\" encoding = \"UTF-8\"?><IDs></IDs>"; $xmlobj = simplexml_load_string($xmloutput); $xmlobj ->addChild("database_code", $db_code); $xmlobj ->addChild("from_date", $from); $xmlobj ->addChild("to_date", $to); for ($i=0;$i<count($output);$i++) { $idobj = $xmlobj->addChild("IDrecord"); $idobj->addChild("id", $output[$i]['id']); $idobj->addChild("status", $output[$i]['status']); } print header("Content-Type: text/xml") . $xmlobj->asXML(); TIA
  16. Thanks heaps, Rajiv. This does just the job!
  17. Thank you for your reply. Unfortunately, I'm getting a "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" error in relation to the $array3= line. Can you help once more?
  18. I have 2 arrays - $array1 = Array ( [0] => A:163 [1] => A:164 [2] => A:50) $array2 = Array ( [0] => Array ( [pid] => A:163 [date] => 2009-11-18 13:19:44 ) [1] => Array ( [pid] => A:102 [date] => 2009-03-27 17:53:49 ) [2] => Array ( [pid] => A:50 [date] => 2009-03-27 11:22:40 ) ) and want $array3 to contain those elements of $array2 where the value of $array 1 = value of $array2['pid'] i.e. $array3 = Array ( [0] => Array ( [pid] => A:163 [date] => 2009-11-18 13:19:44 ) [1] => Array ( [pid] => A:50 [date] => 2009-03-27 11:22:40 )) How can I do this?
  19. Solved the problem. The calling code is now - <?php //http://www.usenet-forums.com/php-language/21143-need-post-xml-file-url.html $xmlfile = file_get_contents("xmlexampledev.xml"); $alternate_opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen("$xmlfile"), 'content'=>"$xmlfile" ) ); $context = stream_context_create($alternate_opts); $fp = fopen('http://www.domain.com/pid/getpids.php', 'r', false, $context); fpassthru($fp); fclose($fp); ?> and the bit that grabs the POST is - $xmlstr = file_get_contents("php://input");
  20. Using the following code on my localhost, I can successfully send an XML file to a specific remote server, and have a response returned. However, the same code moved up to a development server (with appropriate changes to $filename from localhost to dev.domain.etc), yields no response. If I rejig the code so that it reads from an XML file on my localhost rather than a POSTed XML, all works fine on DEV. Here's the code - <?php // based on example at http://en.allexperts.com/q/PHP5-3508/2008/12/Regarding-Sending-XML.htm $data = file_get_contents("xmlexampledev.xml"); $arr= array('xmlparam' => $data); $array= http_build_query($arr); $context_options = array ( 'http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded " . "Content-Length: " . strlen($array) . " ", 'content' => $array ) ); $filename = "http://dev.domain.com/pid/getpids.php"; //$filename = "http://localhost/pid/getpids.php"; // works $context = stream_context_create($context_options); $response = file_get_contents($filename, false, $context); print_r($response); ?> Here's the bit of code that grabs the XML POST - $xmlstr = $_POST['xmlparam']; //if testing via direct file load, use below instead of $_POST above to load xml file as string //$xmlstr = file_get_contents(XML_SOURCE_FILENAME); //convert $xmlstring into SimpleXMLElement $xml = new SimpleXMLElement($xmlstr); TIA
  21. Thanks for your speedy help; will give this a go on Monday. I did actually try what you suggested, but I realise now that I had set up multiple instances of $pidlist[$i]['pid'] = $row['pid']; etc throughout the code, re-initialising i back to 0 at each instance. Thanks so much!
  22. I think this is probably a fairly simple question, but I just can't see the solution! I have this bit of code - $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); foreach ($res as $row) { if ($row[type'] == 3) { //record $pidlist[]['pid'] = $row['pid']; $pidlist[]['date'] = $row['date']; } elseif ($row[type'] == 2){ //collection $interim_pidlist[] = $row['pid']; } } which is yielding the following output for $pidlist- Array ( [0] => Array ( [pid] => changeme:150 ) [1] => Array ( [date] => 2008-07-14 12:02:32 ) [2] => Array ( [pid] => changeme:152 ) [3] => Array ( [date] => 2008-07-14 12:18:17 ) [4] => Array ( [pid] => changeme:65 ) But I want the output to be Array ( [0] => Array ( [pid] => changeme:150 [date] => 2008-07-14 12:02:32 ) [1] => Array ( [pid] => changeme:152 [date] => 2008-07-14 12:18:17 ) ... [/code] I thought the answer would be using such as $pidlist['pid'][], but this yields - Array ( [pid] => Array ( [0] => changeme:150 [1] => changeme:152 ) [date] => Array ( [0] => 2008-07-14 12:02:32 [1] => 2008-07-14 12:18:17...
  23. OK, got it - <?php include_once("example2.php"); $xml = new SimpleXMLElement($xmlstr); //read xml into variables $orderby = (string)$xml->orderby; echo $orderby.'<br />'; foreach ($xml->communities->community as $comm) { echo $comm.'<br />'; } foreach ($xml->PIDs->pid as $ids) { echo $ids.'<br />'; } ?>
  24. I'm trying to parse some XML code. It is working OK at the parent level (e.g. orderby), but not at the child level (communities, PIDs). I'm sure the answer is really simple, but I'm just not seeing it, so I'd appreciate some guidance. Here's the XML - <?php $xmlstr = <<<XML <?xml version="1.0" encoding="UTF-8" ?> <mypids> <orderby>PID</orderby> <communities> <community>278</community> <community>788</community> </communities> <PIDs> <pid>7888</pid> <pid>7889</pid> </PIDs> </mypids> XML; ?> and here's the php - <?php include_once("example2.php"); $xml = new SimpleXMLElement($xmlstr); //read xml into variables $orderby = (string) $xml->orderby; echo $orderby.'<br />'; for($i=0;$i<sizeof($xml->communities->community);$i++){ foreach($xml->communities->community[$i] as $xcommunity){ echo $xcommunity."<br/>"; } } for($i=0;$i<sizeof($xml->PIDs->pid);$i++){ foreach($xml->PIDs->pid[$i] as $xpids){ echo $xpids."<br/>"; } } ?>
×
×
  • 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.