[PHP] Simple code that won't work

2002-12-17 Thread Jacob van Zanen
Hi All,


Reasonably new to PHP and trying to write a code that looks through my
logfiles and reports the lines that contain any of the keywords in my init
file.
However can't seem to get it to work

?
// Open an ini file
if (!($IniContent = file(d:\MyPhp\initORA.ini)))
{
 Print (File could not be opened);
 exit;
}
if (!($FileContent = file(d:\MyPhp\\test.ora)))
{
 Print (File could not be opened);
 exit;
}
while (list ($LineNum, $Line) = each ($FileContent))
{
 while (list($KeyNum, $IniParm) = each($IniContent))
 {
  if (strstr($Line,$IniParm))
 {
  print ($Line);
 }
 }
}
?

If  the part that does not seem to work is the bit that does the comparison.

Anybody have an idea why???

TIA Jack



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Simple code that won't work

2002-12-17 Thread Jason Wong
On Tuesday 17 December 2002 22:25, Jacob van Zanen wrote:
 Hi All,


 Reasonably new to PHP and trying to write a code that looks through my
 logfiles and reports the lines that contain any of the keywords in my init
 file.
 However can't seem to get it to work

 ?
 // Open an ini file
 if (!($IniContent = file(d:\MyPhp\initORA.ini)))
 {
  Print (File could not be opened);
  exit;
 }
 if (!($FileContent = file(d:\MyPhp\\test.ora)))
 {
  Print (File could not be opened);
  exit;
 }
 while (list ($LineNum, $Line) = each ($FileContent))
 {
  while (list($KeyNum, $IniParm) = each($IniContent))
  {
   if (strstr($Line,$IniParm))
  {
   print ($Line);
  }
  }
 }
 ?

 If  the part that does not seem to work is the bit that does the
 comparison.

'=' is an assignment operator, what you want is '==' which is the equality 
operator.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Do you mean that you not only want a wrong answer, but a certain wrong answer?
-- Tobaben
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Simple code that won't work

2002-12-17 Thread Ford, Mike [LSS]
 -Original Message-
 From: Jason Wong [mailto:[EMAIL PROTECTED]]
 Sent: 17 December 2002 14:58
 
 On Tuesday 17 December 2002 22:25, Jacob van Zanen wrote:
  Hi All,
 
 
  Reasonably new to PHP and trying to write a code that looks 
 through my
  logfiles and reports the lines that contain any of the 
 keywords in my init
  file.
  However can't seem to get it to work
 
  ?
  // Open an ini file
  if (!($IniContent = file(d:\MyPhp\initORA.ini)))
  {
   Print (File could not be opened);
   exit;
  }
  if (!($FileContent = file(d:\MyPhp\\test.ora)))
  {
   Print (File could not be opened);
   exit;
  }
 
 '=' is an assignment operator, what you want is '==' which is 
 the equality 
 operator.

Nope, nope, and nope.  Those are quite legitimate assignments of the results of the 
file() calls within the if -- nothing wrong with that.

However, I'd certainly double the backslashes in the pathnames, just in case you 
happen to hit a \x combination that means something -- either that or use single 
quotes so only \' has special meaning!

  while (list ($LineNum, $Line) = each ($FileContent))
  {
   while (list($KeyNum, $IniParm) = each($IniContent))
   {
if (strstr($Line,$IniParm))
   {
print ($Line);
   }
   }
  }
  ?

The following note on the manual page for file() may be of interest here:

 Note: Each line in the resulting array will include the
 line ending, so you still need to use trim() if you do
 not want the line ending present.

(I'm not convinced this is the most elegant way to do what you want, but with the 
addition of trim() it should do the job!)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php