php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2150 String comparison
Submitted: 1999-08-25 13:44 UTC Modified: 1999-09-04 18:41 UTC
From: tri_kar at hotmail dot com Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.12 OS: win98
Private report: No CVE-ID: None
 [1999-08-25 13:44 UTC] tri_kar at hotmail dot com
//IT DID NOT WORK with me
//can some one help me
/*what I am trying to do is compare strings and filter out garbage strings from the user in put by comaring it with my garbage file*/


<html>
<body>
<form>
<?
$gar=file("garbagewords.txt");
$words = explode(" ",$name);
 $temp=0;

 for($i=0; $i<count($words); $i++)
 {
  for($j=0; $j<count($gar); $j++)
  {
   if(($words[$i]==$gar[$j]) && (strlen($words[$i])==	strlen($gar[$j])))
 {
  echo "Garbage =$gar[$j]<br>";
 }

 else if(($words[$i]!=$gar[$j]) && (strlen($words[$i])!= strlen($gar[$j])))
 {
  echo "Words=$words[$i]<br>";
 }
}
}
?>
<form method="post" action="<?php echo $PATH_INFO?>">
Search:<input type="Text" name="name" value=" "><br>
<input type="Submit" name="submit" value="Enter">
</form>
</body>
</html>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-29 11:17 UTC] sas at cvs dot php dot net
What does the script produce and what did you expect? We need more info to be able to help you
 [1999-09-04 18:41 UTC] riffraff at cvs dot php dot net
remember, that file() leaves the '\n''s at the end of the string!
so if garbagewords.txt contains:
riff
raff
$gar[0] is "riff\n" and $gar[1] is "raff\n", which isn't
equal to "riff" or "raff".
see manual of chop() to solve your problem.
also notice, that if $a and $b are strings and $a=$b, than
strlen($a)=strlen($b). you haven't to check it explicitelly.
if this wasn't your problem, write me or report another bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 02:01:31 2024 UTC