Scanning lines in a .txt for specific values
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2805427/how-to-extract-data-from-csv-file-in-php">how to extract data from csv file in php</a>  </p>
</blockquote>



<p>An assignment I have recently received asks of me to make a mock dating site. A lot of the work is provided, and all that is necessary of me is to write the PHP. The part I am stuck on is regarding looking for 'matches' between queried names and names in the .txt file (a database of names already inputted). The text file looks like this:</p>

<pre><code>Jenny,F,28,INTJ,Gentoo,18,30
Michael,M,22,ISTJ,Windows,20,25
...
Name,Gender,Age,Personality,OS,minage,maxage
</code></pre>

<p>The page I am working with prompts me for a name (of one of the people in the .txt file), and then finds potential matches. A 'match' is any person with all of the following: opposing gender, within their respective age ranges, share at least two letters of personality type (eg. ISTP + ESFP = match), and same favorite operating system. It then displays the matches in HTML, which I'm capable of.</p>

<p>My problem is I'm not entirely sure how to cross-reference the text file. I initially thought I should put each line of the .txt into an array element of a larger array:</p>

<pre><code>&lt;?php
    //Initialize the contents of the url (.php?name=$$$) into a variable $inputname
    $inputname = $_GET["name"];
    //Finds how many lines in the singles.txt file
    $lines = count(file("./singles.txt"));
    //Initialize each line into an array
    $matchespre = file("./singles.txt");
?&gt;
</code></pre>

<p>...but I'm not sure how I can search for specific characters (INTJ, M, 30, 40, etc etc).</p>

<p>How do I get my desired result? I'm sorry if it's difficult to understand what my end goal is, the question itself is very hard to follow (in my opinion). Apparently I lack the reputation to post an image, else I'd screengrab the assignment question itself to post.</p>

<p>edit; I think maybe what I'm looking for is a way to put each line of the .txt into a string (eg. string1 = Jenny,F,28,INTJ,Gentoo,18,30; string2 = Michael,M,22,ISTJ,Windows,20,25, etc), then explode() each string into an array, so I have a bunch of arrays. I can then search each array sequentially for matching gender, age range, etc. I just lack the encyclopedia of functions PHP has to offer to know exactly what to do.</p>
