Hi,
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. 3 2177
Patrick wrote: Hi,
I've got the following script:
<? $inhoud = file("/opt/scripts/sc/sc_trans.log"); $inhoud = implode("", $inhoud);
$inhoud_array = explode("\n", $inhoud);
I guess you do this to remove the \n from each line... why don't you
trim() each line instead? 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
print_r($titel1);
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. How do I solve this?
Gr. Patrick.
On Fri, 14 Jan 2005 16:01:05 +0100, Dani CS
<co*****************@yahoo.es.quita-la-merluza> wrote: Patrick wrote: Hi,
I've got the following script:
<? $inhoud = file("/opt/scripts/sc/sc_trans.log"); $inhoud = implode("", $inhoud);
$inhoud_array = explode("\n", $inhoud);
I guess you do this to remove the \n from each line... why don't you trim() each line instead?
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
print_r($titel1);
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.
How do I solve this?
Gr. Patrick.
This is how the logfile looks like:
<01/12/05@11:40:57> [STREAM] Connected to host server
<01/12/05@11:40:57> [DECODE] Opened 218 - Ali B. - Ik ben je zat.mp3
<01/12/05@11:40:57> [CONFIG] WARNING: No InputSamplerate defined,
assuming 44100!
So, I only need the line with [DECODE] in it.
var1 is the date and time
var2 is the text after [DECODE]
Patrick,
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 http://us4.php.net/manual/en/function.preg-match.php
Thanks,
--Kartic This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# to open a file and write to file
# do
f=open('xfile.txt','w')
# this creates a file "object" and name it f.
# the second argument of open can be
|
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the...
|
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much...
|
by: Oliver Knoll |
last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode
(that is just writing, right?). How would one reopen it for reading?
I got the following (which works):
FILE *tmpFile =...
|
by: Rajorshi Biswas |
last post by:
Hi folks,
Suppose I have a large (1 GB) text file which I want to read in
reverse. The number of characters I want to read at a time is
insignificant. I'm confused as to how best to do it. Upon...
|
by: Need Helps |
last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
|
by: John Dann |
last post by:
I'm trying to read some binary data from a file created by another
program. I know the binary file format but can't change or control the
format. The binary data is organised such that it should...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features...
|
by: Derik |
last post by:
I've got a XML file I read using a file_get_contents and turn
into a simpleXML node every time index.php loads. I suspect this is
causing a noticeable lag in my page-execution time. (Or the...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |