Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?
  2. $file   = 'file.txt';
  3. $data   = file_get_contents($file);
  4. $output = [];
  5.  
  6. foreach (explode("\n", $data) as $line) {
  7.     $output[] = explode('|', $line);
  8. }
  9.  
  10. if (empty(end($output)[0])) {
  11.     unset($output[count($output) - 1]);
  12. }
  13.  
  14. $json = json_encode($output);
  15.  
  16. echo '<pre>'; print_r( $json ); echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement