Read txt file

Discussion in 'PHP' started by cwenterprises, Jul 14, 2009.

  1. #1
    Hi,

    I need some help with reading a txt file line by line using PHP so I can then add parts of each line to MYSQL database.

    I have a txt file that looks like this:
    Beyonce - Halo (2:45)
    Metallica - The Day That Never Comes (5:45)

    I need to read the artist name, then the song name and then the length and be able to add it to a database. Anyone know how to retrieve a bit of a line at a time?

    Cheers
     
    cwenterprises, Jul 14, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Use the file() function which will put each line into an array. You can then use a regular expression or a strpos() -> substr() to extract the data you need.
     
    jestep, Jul 14, 2009 IP
  3. cwenterprises

    cwenterprises Peon

    Messages:
    101
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks I will have a go.
     
    cwenterprises, Jul 14, 2009 IP
  4. cwenterprises

    cwenterprises Peon

    Messages:
    101
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Haha did it :p
     
    cwenterprises, Jul 14, 2009 IP