Read and parse BCR text file with PHP

Posted on 2006-05-26
Last Modified: 2006-11-18
Hi. I need to read and parse the contents of a .bcr text file with PHP. I`ve tried using fgetcsv, but I cant`t manage to separate the fields. The text file in question is here: What I need is to print out the time the song played, track and artist. I hope someone can help me, please! Regards.
Question by:wilhelmae
    LVL 29

    Expert Comment

    "CSV" implies that the fields/ values are separated by commas or a separator.
    In the case of your file, fields are obviously fixed-length and non-separated (to be more precise: separated by a variable number of spaces.

    Thus you need to read the file as fixed-width fields.
    Use fgets() to read a line, then split the string into fields, eg

    $rad_field_start=0;// 1st character in the line
    $rad_field_len=14; //length
    LVL 16

    Accepted Solution

    your file use spaces between eache column, try this code
    $data = file('') or die("error");
    $line= array();
    foreach ($data as $l){
    $line[] = preg_split('/[ ]{2,}/',$l);


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now