toledorodney

Search an XML file

Jul 10th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. $emp_file = "/occ/data/xml/directory-results.xml";
  4. $emp=simplexml_load_file($emp_file);
  5.  
  6. $last = '';
  7. $first = '';
  8. $resLast = $emp->xpath("//person[contains(translate(last, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'".strtolower($last)."')]");
  9. $resFirst = $emp->xpath("//person[contains(translate(first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'".strtolower($first)."')]");
  10. $resAll = array_merge($resLast,$resFirst);
  11.  
  12. foreach ($resLast as $p) {
  13.         $x = (int)$p->pidm;
  14.         $Lpidm[$x] = (int)$p->pidm;
  15.         $lastName[$x] = $p->last;
  16.         $firstName[$x] = $p->first;
  17. }
  18. foreach ($resFirst as $p) {
  19.         $x = (int)$p->pidm;
  20.         $Fpidm[$x] = (int)$p->pidm;
  21.         $lastName[$x] = $p->last;
  22.         $firstName[$x] = $p->first;
  23. }
  24. $pidm = array_intersect($Lpidm, $Fpidm);
  25. foreach ($pidm as $i) {
  26.         echo $lastName[$i].", ";
  27.         echo $firstName[$i]."\n";
  28. }
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment