Advertisement
bilelh

Parse RAW Orga

Dec 15th, 2021
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.         //Enter your code here, enjoy!
  3. $str = <<<EOD
  4. [Nom PrΓ©nom]
  5.  
  6. 0
  7.  
  8. 2
  9. Mobile=
  10. Email=
  11. kjddjd
  12. [QQun d'autre]
  13. 0
  14.  
  15. 2
  16. Mobile=02020202
  17. Email=
  18. kjddjd
  19. [Toto]
  20. 0
  21.  
  22. 2
  23. Mobile=080282920
  24. Email=bil@test.me
  25. kjddjd
  26. EOD;
  27.              
  28. $tous = explode('[',$str);
  29. $tab=array_shift($tous);
  30. $carte = [];
  31. foreach ($tous as $v) {
  32.     preg_match('/Mobile=(.*)$/im', $v, $matches);
  33.     preg_match('/Email=(.*)$/im', $v, $matchmail);
  34.     $mobile = (isset($matches[1])) ? trim($matches[1]) : '';
  35.     $mail = (isset($matchmail[1])) ? trim($matchmail[1]) : '';
  36.     $carte[]=array('nom'=>strtok($v, ']'),'mobile'=>$mobile,'Email'=>$mail);
  37. }
  38.  
  39. //print_r($carte);
  40. echo json_encode($carte);
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement