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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tri_kar at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 07:01:29 2025 UTC