codingbenn Posted November 2, 2012 Share Posted November 2, 2012 So basically I have a HUGE text file; download here or the code is like this; FirstName: Wayne, LastName: Brown, CommonName:None, Height: 185, DateOfBirth: Year: 1977, Month: 1, Day: 14, PreferredFoot: Right, ClubId: 1951, LeagueId: 61, NationId: 14, Rating: 54, Attribute1: 56, Attribute2: 53, Attribute3: 47, Attribute4: 61, Attribute5: 36, Attribute6: 49, Rare: 0, ItemType: PlayerGk but this is repeated like 11,480 times(to be exact) but with different information e.g names ect. I have the search working ATM like this; <?php $search = 'Wayne'; $lines = file('cleanedfutplayers.txt'); $found = false; foreach($lines as $line) { if(strpos($line, $search) !== false) { $found = true; echo $line; } } if(!$found) { echo "<i>No match found"; } ?> And atm I get a return of this; BUT i want to filter it out. I want it to just take the values such as getting the value of first name would just get Wayne and the same for the rest of the fields. and i also need some <br> 's in there and some spacing. So how would I go about filtering this? Also how would I add a search box and a button that would give and set the value of the; $search = ''; so for example i THINK the code will be something like this; echo "First Name: ", ['FirstName']; but it isnt because ive tested and it doesnt work? so PLEASE help me! Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2012 Share Posted November 2, 2012 SQL stands for - Structured Query Language. One of the reasons it has been suggested that you use a database for this is because writing a database SQL query statement to do what you want, search (filter) for specific information becomes trivial - $query = "SELECT a, list, of, columns FROM your_table WHERE FirstName = '$search'"; Let a database engine do the work for you, rather than you re-inventing the wheel writing your own code to search in your text data. Also, the compiled code of a database engine will be at least 10x faster at finding the data than your parsed, tokenized, interpreted, relatively slow php code will be at finding the data. Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/#findComment-1389503 Share on other sites More sharing options...
codingbenn Posted November 2, 2012 Author Share Posted November 2, 2012 SQL stands for - Structured Query Language. One of the reasons it has been suggested that you use a database for this is because writing a database SQL query statement to do what you want, search (filter) for specific information becomes trivial - $query = "SELECT a, list, of, columns FROM your_table WHERE FirstName = '$search'"; Let a database engine do the work for you, rather than you re-inventing the wheel writing your own code to search in your text data. Also, the compiled code of a database engine will be at least 10x faster at finding the data than your parsed, tokenized, interpreted, relatively slow php code will be at finding the data. But how do I put all this data into a database? Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/#findComment-1389606 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2012 Share Posted November 2, 2012 But how do I put all this data into a database? See your previous thread. Two different people posted example code showing how you can do this. Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/#findComment-1389610 Share on other sites More sharing options...
codingbenn Posted November 2, 2012 Author Share Posted November 2, 2012 I sorted it actually Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/#findComment-1389613 Share on other sites More sharing options...
codingbenn Posted November 2, 2012 Author Share Posted November 2, 2012 See your previous thread. Two different people posted example code showing how you can do this. turned out I could just add in the text file into the sql and it would filter it Quote Link to comment https://forums.phpfreaks.com/topic/270182-searching-a-text-file-and-filtering-what-is-shown-help/#findComment-1389614 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.