?
Solved

Read and parse BCR text file with PHP

Posted on 2006-05-26
2
Medium Priority
?
277 Views
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: http://radio3.no/rapport/test.bcr. What I need is to print out the time the song played, track and artist. I hope someone can help me, please! Regards.
0
Comment
Question by:wilhelmae
2 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 16774346
"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
$tim_field_start=14;
$tim_field_len=8;
$radio_station=trim(substr($line,$rad_field_start,$rad_field_len));
$time_on_air=trim(substr($line,$tim_field_start,$tim_field_len));
...
0
 
LVL 16

Accepted Solution

by:
dr_dedo earned 1000 total points
ID: 16774920
your file use spaces between eache column, try this code
<?
$data = file('http://radio3.no/rapport/test.bcr') or die("error");
$line= array();
foreach ($data as $l){
$line[] = preg_split('/[ ]{2,}/',$l);
}

print_r($line);
?>
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

829 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