0
<?php
$q = $_REQUEST["q"];
$f = fopen("fence.txt", "r");
while (($line = fgets($f)) !== FALSE) {
   if (strstr($line, $q)) {
       echo "<li>Your Card Number and Expiration Date: $line"; 
   }   // outputs card+expiration date if either one is found in the line
}
?>

I have this code where it takes the input from the user, their card number, and displays that card alongside the expiration date for it.

The code takes the Card numbers and dates from fence.txt.

The data inside of fence.txt shows up as

123456,7/4/2023
111399,4/7/2021
213262,11/13/2030
213268,11/13/2030

When the user searches for card 123456 the result is as follows

Your Card Number and Expiration Date: 123456, 7/4/2023

I've been trying to figure out how I can make it so that it shows up as

Your Card Number: 123456
Expiration Date: 7/4/2023

I've been trying to explode it, but it hasn't worked. What can I do to it? I also want it to say "Not Found" if the card isn't found in the file.

Foxjr
  • 11
  • 3

1 Answers1

0

Please try this:

$res = explode(',', $line);
echo "Your Card Number:". $res[0] ."<br> Expiration Date:". $res[1]; 
Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48