Connecting Tech Pros Worldwide Help | Site Map

function explode

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 13th, 2008, 10:25 AM
lbvox
Guest
 
Posts: n/a
Default function explode

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);
?>

  #2  
Old March 13th, 2008, 11:25 AM
Janwillem Borleffs
Guest
 
Posts: n/a
Default 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
  #3  
Old March 13th, 2008, 12:25 PM
lbvox
Guest
 
Posts: n/a
Default 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
  #4  
Old March 13th, 2008, 04:25 PM
Janwillem Borleffs
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.