开发者

Php input to check against a file

I am not herein asking for anyone to do the work for me, i just need a point in the right direction, since i seem to keep backtracking. =) So my problem is this:

On the website, i have 4 donation perks "boxes" (a list of perks someone will get as a thank you for donating). Now, i am putting an input form on the top, where a person coul开发者_开发问答d type in their name, and if userx has already donated before, but want to check what better perks he could get, he puts in his name, and then it shows only like say boxes 3 and 4.

Boxes 1-4 = VIP, SuperVIP, EliteVIP, EliteModerator.

The form should check against a single file containing all the names/perks-packages, and its already nicely formatted like this:

hvv7:
 subgroups: []
 permissions: []
 group: SuperVip
TEAR_GAS_TEDDY:
 subgroups: []
 permissions: []
 group: EliteVip
KMoore11:
 subgroups: []
 permissions: []
 group: SuperVip
EanEuropean:
 subgroups: []
 permissions: []
 group: Moderator
powerwind:
 subgroups: []
 permissions: []
 group: Vip

Again, i really just need a push in the right direction, but any help/answers will be much appreciated. Reason i am here today is because, i know of a few ways to check the word already, but what baffles me is checking the word, and then getting the info 3 lines down, having that return and then changing some div's visibily (to hide the ones userx already has)

EDIT: Hmm, still researching, i wonder if it would be easier to just get the name/group into mysql, and then having the script just read that instead lol.


Use regex from an offset of the username to grab the first group below that username. Like so:

$data = file_get_contents("file.txt");
$username = "hvv7"; // Example username
$offset = stripos($data, $username);
$group = "";    

if(preg_match("/group:([ A-Z0-9]+)/i", $data, $matches, PREG_OFFSET_CAPTURE, $offset))
{
    $group = $matches[1][0];
}

echo $group; // Something like Vip


$content = get_file_contents('file.txt');
$content = explode("\n",$content);//split by line...
$group = $content[3];// returns "group: SuperVip"

// the 3 is the indexed number. or something similar in those lines... not sure if explode would work but hey give it a go :)


The clue is in the name - DATA base.

PHP does not have the file locking locking semantics required for managing concurrent access to flat file data. And that's before you start considering the complications of seeking within the file and parsing its structure.

Use a database.


use the other answers in order to fetch the type of moderator. in terms of the jquery on the page, i would put all the names in an array in the order of hierarchy so

var groups = ["Vip","Moderator","SuperVip","EliteVip","EliteModerator"]; 

Then say your variable is

var usergroup = "whatevertheuserGroupYouGetFromPHP";

var index = groups.indexOf(usergroup);

var tempGroups = groups;

tempGroups.splice(0,index);

$.each(tempGroups,function(index,value) {
      $("#" + value).show();
});

and make all ur boxes CSS be initially have display:none;

and also give them each the ID that matches the group names. that should work


You can use JSON format for your file. Using json_encode and json_decode functions you can easily read, modify and write your data structure.

For example you can have an array like this:

$data = array(
    "hvy7" => array(
        "subgroups" => array(),
        "permissions" => array(),
        "group" => "SuperVip"
    ),
    "TEAR_GAS_TEDDY" => array(
        "subgroups" => array(),
        "permissions" => array(),
        "group" => "EliteVIP"
    )
);

Of course this is not a good example of data structure. But i think you'll get the point. You can access them as normal php object. Than you can export as JSON format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜