Schlo_50 Posted April 11, 2008 Share Posted April 11, 2008 Hi there, I am trying to create an advanced search feature where by a person can search through a list of job vacancies to find suitable jobs for candidates. The last stage of my script is meant to search through a .DAT file for keywords stored in my array. I can open the file using fopen() but im not sure what I need to do to find my key words and then print out the full file contents. Im assuming preg_match() but im useless with this function. Could somebody help? My code is below: if ($salary >= $from && $salary <= $to){ // If there are vacancies matching the wage band grab id and start searching descriptions for skill matches $handle = fopen("data/$vacancy_id.DAT", "r"); // split skills up in array $search = $_POST['b']; $skill = (str_word_count($search, 1, 'àáãç')); foreach ($skill as $var){ // try to match preg_match_all($var, $handle) // print out matches print "Found Match!<br />"; } } ANybody got any ideas? Much appreciated! Thanks Quote Link to comment Share on other sites More sharing options...
zq29 Posted April 11, 2008 Share Posted April 11, 2008 fopen() just creates a file system pointer resource, you need to use it in conjunction with fread() to get the contents of the file. Though, for this purpose, it'd probably be better to use file_get_contents(). If you are only matching strings, and not patterns, RegEx functions are probably a waste of resources, you might be better off using something like strpos(). <?php $contents = file_get_contents("foo.dat"); $skill = array("lorem","ipsum","dolar","sit","amet"); $found = false; foreach($skill as $s) { if(strpos($content,$s)) { $found = true; break; } } echo ($found) ? "Matches found in:<br />".$content : "No matches."; ?> Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted April 11, 2008 Share Posted April 11, 2008 It depends on format of your file and if you want to return, for example, number of the row (= number of record). Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted April 11, 2008 Author Share Posted April 11, 2008 The file is a .DAT file containing a description. I'd simply want to print out the file contents if a match is found. Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted April 12, 2008 Share Posted April 12, 2008 .DAT is not a unified format, it's merely a file extension. As I said, we need to know how is your file organized. Quote Link to comment 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.