reading a file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I've got the following script:

$inhoud = file("/opt/scripts/sc/sc_trans.log");
$inhoud = implode("", $inhoud);

$inhoud_array = explode("\n", $inhoud);

for($i=0; $i < count($inhoud_array); $i++){
   $titel1 = explode("[DECODE] Opened ",$inhoud_array[$i]);
   $titel2 = explode(".mp3",$titel1[1]);
   $titel = $titel2[0];

   $part1 = explode("<",$inhoud_array[$i]);
   $part2 = explode(">",$part1[1]);
   $tijd= $part2[0];
   $tijd= ereg_replace("@"," ", $part2[0]);

   echo "[$tijd] $titel\n";

While running this I get:

PHP Notice:  Undefined offset:  1 in /opt/scripts/shoutcast/crphp on
line 9

How do I solve this?

Gr. Patrick.

Re: reading a file

Patrick wrote:
Quoted text here. Click to load it

I guess you do this to remove the \n from each line... why don't you
trim() each line instead?

Quoted text here. Click to load it


My guess is you only get one element when you explode()
$inhoud_array[$i], and it will be $titel[0].

Without seeing a sample line from /opt/scripts/sc/sc_trans.log there's
little more to say.

Quoted text here. Click to load it

Re: reading a file

On Fri, 14 Jan 2005 16:01:05 +0100, Dani CS

Quoted text here. Click to load it
This is how the logfile looks like:
assuming 44100!

So, I only need the line with [DECODE] in it.
var1 is the date and time
var2 is the text after [DECODE]

Re: reading a file


There is no $titel1[1] element.

Your first and third lines do not have the "[DECODE] Opened" patterns,
so explode returns in $titel1 the original string as an array...meaning
$titel1[0] == $inhoud_array[$i] and there is no $titel1[1]! That is why
PHP is complaining about undefined offset.

Since you doing some kind of pattern matching, you should probably look
into Regular Expressions. Please refer


Site Timeline