2016-12-27 6 views
-2

テキストボックスフォームを作成する方法phpのテキストファイルをプロモーションコードフォームに置き換えます。私のcsgoギャンブルサイト用のテキストファイルです。テキストファイル/promo/codes.txtからコードを引き換えたいと思っています。彼らは無用にテキストファイルが、イムのリストから任意のコードを使用することができるように:(テキストボックスフォームを作成する方法は、phpのテキストファイルをプロポコード形式に変換しますか?

答えて

0

それは、ファイルの形式に完全に依存し、それを作る

例:。

ZQC01 
ZQR92 
ZQA84 
ZQD73 

プロモーションコードがこのファイルに含まれているかどうかを確認して後で削除する:

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 

    $myPromoCode = isset($_POST['promocode']) ? $_POST['promocode'] : false; 
    $contents = file_get_contents('/path/to/file.txt'); 
    $promoCodes = explode("\n", $contents); 

    // Check if the promo code is present in the file 
    if ($myPromoCode && in_array($myPromoCode, $promoCodes)) { 

     // Find the corresponding key 
     $key = array_search($myPromoCode, $promoCodes); 

     // Remove the code 
     unset($promoCodes[$key]); 

     // Write coes back to file 
     $contents = implode("\n", $promoCodes); 
     file_put_contents('/path/to/file.txt', $contents); 

    } else { 
     die("Promotion code doesn't exist"); 
    } 

} 
?> 
<form method="POST" action="<?= $_SERVER['PHP_SELF']; ?>"> 
    <input type="text" name="promocode" /> 
    <button type="submit">Redeem</button> 
</form> 
関連する問題