Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

function explode

Question posted by: lbvox (Guest) on March 13th, 2008 10:25 AM
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);
?>
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Janwillem Borleffs's Avatar
Janwillem Borleffs
Guest
n/a Posts
March 13th, 2008
11:25 AM
#2

Re: function explode
lbvox schreef:
Quote:
Originally Posted by
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:
Originally Posted by
// 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's Avatar
lbvox
Guest
n/a Posts
March 13th, 2008
12:25 PM
#3

Re: function explode
On 13 Mar, 12:20, Janwillem Borleffs <j...@jwscripts.comwrote:
Quote:
Originally Posted by
lbvox schreef:Hello, I have created this script, but I do not succeed toinsert the
Quote:
Originally Posted by
function "explode ()" for being able to gain given following dates
---- ($host="hostname" / $msg="msg" /$date="date")

>
[...]
>
Quote:
Originally Posted by
* *// 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's Avatar
Janwillem Borleffs
Guest
n/a Posts
March 13th, 2008
04:25 PM
#4

Re: function explode
lbvox schreef:
Quote:
Originally Posted by
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

 
Not the answer you were looking for? Post your question . . .
184,038 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors