user9151888
user9151888

Reputation: 155

make sure txt file has a certain text

I have got this script:

$counter = file_get_contents(strtolower($_GET["username"]).".txt") - 1;

I want the "1" to change to this:

echo $_GET["amount"];

I want that script to run if the allocated txt file <?php echo $_GET["username"];?>.txt has enough in it.

For example, if the txt file has "8" in it, and echo $_GET["amount"]; was equal to 7, the txt file has enough in it. But if the txt file has "6.05" in it, and echo $_GET["amount"]; was equal to 7, the txt file doesn't have enough in it.

How can I do this?

Upvotes: 1

Views: 54

Answers (1)

YouneL
YouneL

Reputation: 8361

Pass the amount as parameter into your url, it should be something like this:

<a href="http://example.com/path?username=jhon&amount=1"></a>
                                               ^^^^^^^^

Or if the amount is a variable:

$username = 'jhon'
$amount = 6;

echo '<a href="http://example.com/path?username='. $username .'&amount='. $amount .'"></a>';

Then you can get the amount like this:

$counter = file_get_contents(strtolower($_GET["username"]).".txt") - $_GET["amount"];

if ($counter > 0) {
    // file has enough
} else {
    // file doesn't has enough
}

Upvotes: 2

Related Questions