Re[4]: [PHP] erge on a text file
| From: | Richard Kurth | Date: | Sun, 10 Sep 2000 21:44:04 +0000 |
| Subject: | Re[4]: [PHP] erge on a text file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16082@lists.php.net to get a copy of this message | ||
Hello Adam,
It does not seem to work when I put a number that is in the file in
$number it says the number has been found but if I put a number that
is not in the file it still says the number has been found. It also
loops through all the numbers and says it has been found for every
number in the file. I put an exit; after the $found =1; and that seemed
to stop the loop on the display. This number has to be an exact match
to the number because this is a check to a credit card purchase
Sunday, September 10, 2000, 2:51:47 PM, you wrote:
AC> Ok, I would use something like this:
AC> $number ="1494211";
AC> $data = file('data1.txt');
AC> for($a=0;$a<count($data);$a++){
AC> if($number = $data[$a]){
AC> echo "The number has been found";
AC> $found = 1;
AC> }
AC> }
AC> if(!$found){
AC> echo "The number was not found";
AC> }
AC> I think that should work, if you have any problems or if you want to know
AC> how it works just give me a yell.
AC>> Could you tell us what format the the file is in? Is each number on a
AC> new
AC>> line?
AC> Yes each number is on a new line like this
AC> 1494211
AC> 2368963
AC> 6902920
AC> 4335433
AC> 0700043
AC> 9235075
AC> 6720910
AC> 9038221
AC> 7984004
AC> 9234361
AC>> I am trying to get this script to look at a text file with a list of
AC>> numbers a see if the number is there. Every time I run this script it
AC>> tells me that it is not there even when I know that it is. Is there a
AC>> better way of doing this.
AC>> <?php
AC>> $webfile = "data1.txt";
AC>> $number ="1494211";
AC>> if(strlen($number) != 7) {
AC>> echo "Sorry, but $number is not a valid number\n";
AC>> exit;
AC>> }
AC>> if (ereg( $number , $webfile)){
AC>> exit;
AC>> }
AC>> else {
AC>> echo "This not a valed number $number";
AC>> }
?>>>
--
Best regards,
Richard mailto:rkurth@pacifier.com