regex - With PHP filter a textfile into an A-Z listing -


I have a text file that reads:

  9123 Bellevue Court 5931 Walnut Creek RD Andrew Bailey Chris Drew Earl Fred Gerald Henry Ida Jake Common Larry Manny Nomar Omar Perry Quest Raphael State Talmman Uruguayan Wickson Whale Xavier Yellow Zebra What do I need to do to make me an edge list? .. then:  
  # ABCDGGJKLMNOPQRSTUWWXYZ  

And when you click on the letter, it will start with only one I will click on A, and if I click only on the # symbol, then only words starting with numbers are clicked.

I was thinking of using a regular expression to complete it but I did not want to create 27 different pages. So is there a way to call the letter at the end of the URL? Like doing something that

  http: //mywebsite/directory.php? Letter = A  

A very simple approach:

Text file Read in:

  $ inputfile = file ('words.txt');  

Then, after adjusting the input ( $ letters = $ _GET ['letter'] ), you can create a regex:

< Pre> $ regex = '/^'.$letter.'/' ';

and filter the rows you want to show:

  $ result = preg_grep ($ regex, $ inputfile);  

The rest is just a matter of outputting the good HTML (or whatever the output will be)


Keep in mind: When pages are often read, this is a database Very fast for files stored in


EDIT: Forget to mention: To get # to work, you also have a look at the caching system Should the problem be loaded sometime in the future. You need to add a line with the following:

  if ($ letters == '#') $ letters = '[0-9]';  

Get regex to work again.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -