Connecting Tech Pros Worldwide Forums | Help | Site Map

function explode

lbvox
Guest
 
Posts: n/a
#1: Mar 13 '08
Hello, I have created this script, but I do not succeed to insert the
function "explode ()" for being able to gain given following dates
---- ($host="hostname" / $msg="msg" /$date="date")

<?php
// Open file in reading
$identificatore=fopen ("test.txt", "r");

// text to find in the file
$host="hostname";
$msg="msg";
$date="date";
$risultato="$host|$msg|$date";
$counter=0;

// execute the cycle until the end of the file
while (!feof ($identificatore)){

// incremen the $counter of the one unit
$counter ++;

// registry in the variable $buffer the content of the line
$buffer=fgets($identificatore, 4096);

// control with eregi if to the inside of $buffer there is the text
that I am trying
// if the outcome is positive stamp its content
if (ereg($risultato, $buffer))


echo "$buffer<br>";
}

// close the file
//fclose ($identificatore);
?>

Janwillem Borleffs
Guest
 
Posts: n/a
#2: Mar 13 '08

re: function explode


lbvox schreef:
Quote:
Hello, I have created this script, but I do not succeed to insert the
function "explode ()" for being able to gain given following dates
---- ($host="hostname" / $msg="msg" /$date="date")
>
[...]
Quote:
// registry in the variable $buffer the content of the line
$buffer=fgets($identificatore, 4096);
>
Insert the following below this line:

list($hostname, $msg, $date) = explode('|', $buffer);


JW
lbvox
Guest
 
Posts: n/a
#3: Mar 13 '08

re: function explode


On 13 Mar, 12:20, Janwillem Borleffs <j...@jwscripts.comwrote:
Quote:
lbvox schreef:Hello, I have created this script, but I do not succeed toinsert the
Quote:
function "explode ()" for being able to gain given following dates
---- ($host="hostname" / $msg="msg" /$date="date")
>
[...]
>
Quote:
* *// registry in the variable $buffer the content of the line
* *$buffer=fgets($identificatore, 4096);
>
Insert the following below this line:
>
list($hostname, $msg, $date) = explode('|', $buffer);
>
JW
I have followed as you have indicated to me

<?php
// apro il file in lettura
$identificatore=fopen ("test.txt", "r");

// testo da trovare all'interno del file
$host="hostname";
$msg="msg";
$date="date";
$risultato="$host|$msg|$date";
$counter=0;

// eseguo il ciclo fino alla fine del file
while (!feof ($identificatore)){

// incremento il $counter di una unità
$counter ++;

// registro nella variabile $buffer il contenuto della linea
$buffer=fgets($identificatore, 4096);
list($hostname, $msg, $date) = explode('|', $buffer);

// controllo con eregi se all'interno di $buffer c'è il testo che sto
cercando
// se l'esito è positivo stampo a video il suo contenuto
if (ereg($risultato, $buffer))


echo "$date<br>";
echo "$hostname<br>";
echo "$date<br>";
}

// chiudo il file
//fclose ($identificatore);

But Now the output it does not work
the output show all file
Janwillem Borleffs
Guest
 
Posts: n/a
#4: Mar 13 '08

re: function explode


lbvox schreef:
Quote:
But Now the output it does not work
the output show all file
That's probably because the ereg() match only succeeds when $risultato
is exactly "hostname|msg|date".

For a quick test, you should get rid of the ereg call...


JW
Closed Thread


Similar PHP bytes