Jump to content

[SOLVED] how to match wild cards in php


php1

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.