0

I get a user.txt file. There are all the users saved in this format:

Vorname: Michael | Nachname : Schmidt | Username: DarkDecipio | Passwort: 3609e297fb0b6fb1105cba71d5c024b3
Vorname: John | Nachname : Doe | Username: Dummy | Passwort: d78c03d72e72b44a131d255aec3c8a11

Now when a new User send a register form to the php file, i want to look, if the username is already taken. So i must search all Username's, if there the sended username. But i can't do it with strstr() or something like that, because the Prename (Vorname) or Surname (Nachname) can be the same like the Username. Or the username can include a part of the sended username...

Hope you understand it.
Note: I know it's a ugly solution to save users in a text file, but this is a project in my school and we MUST use textfiles...

4

1 に答える 1

1

頭のてっぺんから、2つのオプションを考えることができます。$line がファイルの現在の行で、'DarkDecipio' を探しているとします。

まず、正規表現を使用して、必要なセクションを確実に取得します。

if ( preg_match('/Username:\s*DarkDecipio/', $line) ) {
    echo 'Match';
}

次に、行を | で分割します。次に、各配列の 3 番目の項目で strstr を使用します。

$items = explode('|', $line);
if ( strstr($items[2], 'DarkDecipio') ) {
    echo 'Match';
}
于 2012-12-21T22:47:40.820 に答える