Auto Complete (PHP) Searching in Txt File

0

File txt

111111 Nome Sobrenome
222222 Nome Sobrenome
333333 Nome Sobrenome

Field to fill in

<span>Aluno</span> : <input id="entry" type="text" name="test">

How can I make it so that when the user types in the auto registration name or complete (searching in the .txt file) and save in $ enrollment only with the registration number?

The number can vary the number of characters, but always appears at the beginning.

Is it possible? Can anyone help me?

    
asked by anonymous 28.02.2018 / 18:00

1 answer

0

You have to study PHP's face functions, for example, instead of asking here, you can go to Google and type: "how to split the string" which is "how to split / cut a string", will come the function explode() for example, from there you implement. Another thing: "how to get content from a txt file" that is "how to get content from a txt file" then the PHP documentation will appear file_get_contents() .

Example:

<?php
$contents = file_get_contents("file.txt");

$rows = explode("\n", $contents);
$cols = [];
foreach ($rows as $row) {
  $cols[] = explode(" ", $row);
}

Now you have an array like this:

[
  ["1", "Marcelo", "Rafael"],
  ["2", "Ana",     "Clara"],
  ["3", "Berta",   "Jota"]
]

Now, since you want to autocomplete, you should use Ajax, so just study if you do not know. Sites to learn:

w3 is more practical and fast W3Schools Ajax

or MDN that is more "upgraded"
MDN Ajax

I did not answer your question directly, but I'm here to help, flw.

    
28.02.2018 / 19:01