php1 Posted June 26, 2008 Share Posted June 26, 2008 hi every one i have a text box in my form in which we can enter date and list files with that date in there file name. The file name is in the format (Date_time_from_to_duration.wav). my problem is that i have to enter wild cards in date text box and return all file that matches that pattern. ie if 01-01-200? then display all files in the day from yeay 2000 - 2009 if *-10-* then display all files in the 10th(october) of all the years like this all cases i have to do. i treid a lot and was not able to do anything. can anybody help on this. i have no idae on how to achieve this. very urgent Quote Link to comment Share on other sites More sharing options...
Rowno Posted June 26, 2008 Share Posted June 26, 2008 I don't understand, what exactly do you want to do? Quote Link to comment Share on other sites More sharing options...
php1 Posted June 26, 2008 Author Share Posted June 26, 2008 i need to perform wildcard character matching. i have a text box in my form where we have to enter date. if i enter the date 1-1-2007 then click search it displays all files of this particular date. i also want to display files when i enter in the text box like below: (1) 1-1-200? then display all files 2000- 2009 ie ? have to replace one character (2) ?-?-200? then display all files which have 1-1-2001 , 1-2-2009 like that all files which have 200 in the year field (3) 1-1-* must display all files of jan 1st like that i have to match for wild cards and display files did u understand my requirement Quote Link to comment Share on other sites More sharing options...
corylulu Posted June 26, 2008 Share Posted June 26, 2008 well first off.... are these dates entered seperately from day to month and to year? or do you just type in 01-01-2000 if you enter them seperately and want to have the outcome of just typing in 200? and getting it to post 2000-2009 then all you really need to do is make a function that takes in the year value, then run it through an if-else statement that asks if the variable is < 1000. and if it is have it run a For loop that muliplies it by ten and adding one to it 10 times until it gets to 2009. Each time it adds one have it posts all the posts that fell on that date and then continue adding. Once the loop is done you are set. as for the other part... im not sure what your asking Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 not sure what you're asking ditto. these questions need to be more clear Quote Link to comment Share on other sites More sharing options...
php1 Posted June 26, 2008 Author Share Posted June 26, 2008 i want to perform wild card matching * : one or more characters ? : one character Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 26, 2008 Share Posted June 26, 2008 You can match filenames with wildcards using the glob() function. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 If these filenames are in a database you can do SELECT * FROM 'Files' WHERE file_name LIKE '%-10-%' OR '%01-01-200%' or modify accordingly. I prefer to keep track of files in a database. Easier to search for info(to me, anyways) Quote Link to comment Share on other sites More sharing options...
php1 Posted June 26, 2008 Author Share Posted June 26, 2008 thank u for all you replies.. i am new to php.. so please tell me how to use glob() function its is not sure where the wild card comes..it depends on user input sometimes it may be ?-?-*07 some times *-*-* some times *?-*?-2*8 so how to achieve all these different things Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 If we tell you, you wont learn anything. You need to just read up on each of these things. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 26, 2008 Share Posted June 26, 2008 You should only allow one type of wildcard, the asterisk, and then simply feed the input string to glob(), as its only argument. Asterisks in glob() is treated like wildcard strings, so you'll only need one asterisk to match several characters. To get an array with all 'October' wav files in the directory "wav_folder", glob('wav_folder/*-10-*.wav') should work. Just read the manual and try it out! You can return here, if anything goes wrong. Quote Link to comment Share on other sites More sharing options...
php1 Posted June 26, 2008 Author Share Posted June 26, 2008 thank you, i will try it out and get back to you when in doubt Quote Link to comment Share on other sites More sharing options...
php1 Posted July 2, 2008 Author Share Posted July 2, 2008 i got the wild cards mathching . i have write one function for this. if(wildcmp(tes?1.*,test1.txt) { echo "match found"; } else { echo "no match"; } function wildcmp($wild, $string) { $cp=0; $mp=0; $w = str_split($wild); $s = str_split($string); $i = 0; $j = 0; $cw = count($w); //count of wild $cs = count($s); //count of string while (($i<$cs) && ($w[$j] != "*")) { if (($w[$j] != $s[$i]) && ($w[$j] != "?")) { return 0; } $i++; $j++; } while ($i<$cs) { if ($j<$cw && $w[$j] == "*") { if (($j++)>=$cw) { return 1; } $mp = $j; $cp = $i+1; } else if ($j<$cw && ($w[$j] == $s[$i] || $w[$j] == "?")) { $j++; $i++; } else { $j = $mp; $i = $cp++; } } while ($j <$cw && $w[$j] == "*" ) { $j++; } return $j>=$cw; } 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.