Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Enter your code here, enjoy!
- $str = <<<EOD
- [Nom PrΓ©nom]
- 0
- 2
- Mobile=
- Email=
- kjddjd
- [QQun d'autre]
- 0
- 2
- Mobile=02020202
- Email=
- kjddjd
- [Toto]
- 0
- 2
- Mobile=080282920
- Email=bil@test.me
- kjddjd
- EOD;
- $tous = explode('[',$str);
- $tab=array_shift($tous);
- $carte = [];
- foreach ($tous as $v) {
- preg_match('/Mobile=(.*)$/im', $v, $matches);
- preg_match('/Email=(.*)$/im', $v, $matchmail);
- $mobile = (isset($matches[1])) ? trim($matches[1]) : '';
- $mail = (isset($matchmail[1])) ? trim($matchmail[1]) : '';
- $carte[]=array('nom'=>strtok($v, ']'),'mobile'=>$mobile,'Email'=>$mail);
- }
- //print_r($carte);
- echo json_encode($carte);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement