Auto Complete (PHP) Searching in Txt File

Asked

Viewed 71 times

0

txt file

111111 Nome Sobrenome
222222 Nome Sobrenome
333333 Nome Sobrenome

Field to fill

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

How do I get it done so that when the user type the auto name or license plate complete (searching the.txt file) and save in $license plate only with the number plate?

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

Is it possible? Someone can help me?

1 answer

0


You have to study the functions of PHP guy, for example, instead of asking here, you can go on Google and type: "how to split a string" which is "how to split/cut a string", will come the function explode() for example, then you implement. Another thing: "how to get content from a txt file" which is "how to get content from a txt file" from there in 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 Voce wants to autocomplete, Voce should use Ajax, so only study if you don’t know. Sites to learn:

W3 is more practical and fast
W3schools Ajax

or MDN which is more "updated"
MDN Ajax

I didn’t answer your question directly, but I’m here to help, flw.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.