PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Read a file codeigniter

 February 19, 2022     codeigniter, xcode-instruments     No comments   

Issue

I need to read this file:

AVRAMOV P   ATALANTA    1   1   0
FREZZOLINI  P   ATALANTA    1   1   0
SPORTIELLO  P   ATALANTA    1   16  15
BIAVA   D   ATALANTA    8   9   1
EMANUELSON  D   ATALANTA    7   5   -2
STENDARDO   D   ATALANTA    7   9   2
BENALOUANE  D   ATALANTA    6   8   2
DRAME'  D   ATALANTA    5   5   0

I read this file, but I need to have some operation which I can work on string. Anyone can suggest me any method?


Solution

It's hard to tell what kind of string operation you're looking to do, but if you want to split the fields, you could do something like this:

<?php
$res = fopen('myfile.txt', 'r');
$data = array();

while (($line = fgets($res)) !== false) {
    $data[] = preg_split('/\s{2,}/', $line);
}

fclose($res);

This will create an array of lines, each line containing an array of fields separated by two or more spaces, for example:

[
    [
        'AVRAMOV',
        'P',
        'ATALANTA',
        '1',
        '1',
        '0'
    ],
    [
        'FREZZOLINI',
// ...


Answered By - Mikkel
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing