Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. $file_handle = fopen('fixy.txt', 'r');
  2.  
  3. while ($line = fgets($file_handle)) {
  4. $output[] = array(
  5. 'title' => trim(substr($line, 0, 50)),
  6. 'code' => trim(substr($line, 50, 5)),
  7. 'date' => trim(substr($line, 55, 8)),
  8. 'writer' => trim(substr($line, 63, 50))
  9. );
  10. }
  11.  
  12. fclose($file_handle);
  13.  
  14. $information['type1'] = array(
  15. array('name' => 'title', 'position' => 0, 'length' => 50),
  16. array('name' => 'code', 'position' => 50, 'length' => 5),
  17. array('name' => 'date', 'position' => 55, 'length' => 8),
  18. array('name' => 'writer', 'position' => 63, 'length' => 50)
  19. );
  20. //there will also be a type 2, 3 and so on...
  21.  
  22. $type = $information['type1'];
  23.  
  24. ...
  25. while ($line = fgets($file_handle)) {
  26. ...
  27. $type['name'] => trim(substr($line, $type['position'], $type['length'])),...
  28. ...
  29. }
  30.  
  31. $information['type1'] = array(
  32. array('name' => 'title', 'position' => 0, 'length' => 50),
  33. array('name' => 'code', 'position' => 50, 'length' => 5),
  34. array('name' => 'date', 'position' => 55, 'length' => 8),
  35. array('name' => 'writer', 'position' => 63, 'length' => 50)
  36. );
  37.  
  38. $type = $information['type1'];
  39.  
  40. $file_handle = fopen('fixy.txt', 'r');
  41.  
  42. while ($line = fgets($file_handle))
  43. {
  44. $output[$type['name']] = trim(substr($line, $type['position'], $type['length']));
  45. }
  46.  
  47. fclose($file_handle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement