Connecting Tech Pros Worldwide Help | Site Map

function explode

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

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, 01:25 PM
lbvox
Guest
 
Posts: n/a

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, 05:25 PM
Janwillem Borleffs
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
explode Davide answers 4 March 28th, 2007 12:15 PM
explode() equivalent in .net the friendly display name answers 4 November 22nd, 2005 08:56 PM
explode() equivalent in .net the friendly display name answers 0 November 22nd, 2005 08:56 PM
explode() equivalent in .net the friendly display name answers 2 July 22nd, 2005 12:28 AM