Posted By

dvdrtrgn on 09/09/08


Tagged

test res


Versions (?)

restest.php


 / Published in: PHP
 

URL: http://homepage.mac.com/dr_turgeon/tester.html

various junk chunks

  1. <?php
  2.  
  3. $base = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService";
  4. $query = "";
  5.  
  6. $params = Array(
  7. 'AWSAccessKeyId'=> '089TSKBGSRMRZAG5VF82',
  8. 'Operation' => "ItemSearch",
  9. 'SearchIndex' => 'Books',
  10. 'ResponseGroup' => 'SalesRank',
  11. 'Keywords' => "O'Reilly",
  12. );
  13.  
  14. foreach ($params as $key => $value){
  15. $query .= "&$key=" . urlencode($value);
  16. }
  17. $url = "$base$query";
  18.  
  19. echo '<pre>';
  20.  
  21. $xml = file_get_contents($url);
  22. //$xml = preg_replace('/></', ">\n<", $xml);
  23. //$xml = domxml_xmltree($xml);
  24. $xml = simplexml_load_string($xml);
  25.  
  26. echo '<style>td{border:1px solid red;}</style>';
  27. echo '<table><tr><td>';
  28. echo '<pre>';
  29. ttn1( eko($xml) );
  30. echo '</td><td>';
  31. echo '<pre>';
  32. ttn2( obv($xml) );
  33. echo '</td></tr></table>';
  34.  
  35.  
  36. function ttn1($res){
  37. $reg = '/\s+\(/'; $rep = " ( ";
  38. $res = preg_replace( $reg, $rep, $res);
  39. $reg = '/\s+\)/'; $rep = " ) ";
  40. $res = preg_replace( $reg, $rep, $res);
  41. $reg = '/\ {3}/'; $rep = " ";
  42. $res = preg_replace( $reg, $rep, $res);
  43. echo $res;
  44. }
  45. function ttn2($res){
  46. $reg = '/=>\s+/'; $rep = " => ";
  47. $res = preg_replace( $reg, $rep, $res);
  48. $reg = '/(\n\s+?})(\n\s+?})?(\n\s+?})?(\n\s+?})?/';
  49. $rep = "$4$3$2$1";
  50. $res = preg_replace( $reg, $rep, $res);
  51. $reg = '/}\n\s+}/'; $rep = "} }";
  52. $res = preg_replace( $reg, $rep, $res);
  53. $res = preg_replace( $reg, $rep, $res);
  54. echo $res;
  55. }
  56. function obv($x){ ob_start();var_dump($x);$s=ob_get_clean();ob_end_flush();return $s;}
  57. function eko($x){ return htmlspecialchars(print_r($x, TRUE), ENT_QUOTES); }
  58. ?>

Report this snippet  

You need to login to post a comment.