Re: [PHP] Show Filename using Wildcards
Ave, Hmmm... Not familiar with glob() at all... Let me dig! Thanks! ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² On 3/30/07 5:23 AM, "Robin Vickery" <[EMAIL PROTECTED]> wrote: > > yeah, you use glob() > > http://www.php.net/glob > > foreach (glob("${phone}*.ext") as $filename) { > //... > } > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
On 29/03/07, Rahul Sitaram Johari <[EMAIL PROTECTED]> wrote: Ave, I have a script where I have to provide a Download Link to a file associated with a record. The common thing between the record & filename is the phone number. But the filenames have dates & other symbols besides the phone number as well. They all do begin with a phone number though. How can I match a filename with a record using wildcards? For example, let¹s say someone pulls up a record for phone field: 515515515 The files associated with this record could be 515515515031307 or 5155155150325T(2). So you can see the filenames do begin the phone number in the record, but they contain additional chars. What I need is something that can pull up all 515515515*.ext Can I do this in PHP? yeah, you use glob() http://www.php.net/glob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
Also, you should validate the phone number (make sure it contains only numerical digits) before using it on the command line. I wouldn't trust the data to build a command line. -Roberto Rahul Sitaram Johari wrote: > ;) > > Point taken! > > exec("find /Users/rjohari/Documents/XFER/espi -type f name > ".$row['PHONE']."*.vox", $files); > foreach ($files as $value) { > echo basename($value).""; > } > ?> > > :) > > Thanks > > ~~~ > Rahul Sitaram Johari > CEO, Twenty Four Seventy Nine Inc. > > W: http://www.rahulsjohari.com > E: [EMAIL PROTECTED] > > ³I morti non sono piu soli ... The dead are no longer lonely² > > > On 3/29/07 4:58 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > >> DON'T commit suicide mate :) >> >> What if you one day move the path? ;) >> >> >>> -Original Message- >>> From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] >>> Sent: Thursday, March 29, 2007 9:54 PM >>> To: Peter Lauri; PHP >>> Subject: Re: [PHP] Show Filename using Wildcards >>> >>> Ave, >>> >>> This Works!! >>> >>> >> exec("find /Users/rjohari/Documents/XFER/espi -type f -name >>> ".$row['PHONE']."*.vox", $files); >>> foreach ($files as $value) { >>> echo substr($value,35).""; >>> } >>> ?> >>> >>> THANKS! >>> >>> ~~~ >>> Rahul Sitaram Johari >>> CEO, Twenty Four Seventy Nine Inc. >>> >>> W: http://www.rahulsjohari.com >>> E: [EMAIL PROTECTED] >>> >>> ³I morti non sono piu soli ... The dead are no longer lonely² >>> >>> >>> >>> On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: >>> >>> >>>> [Peter Lauri - DWS Asia] >>>> >>>> Hi, >>>> >>>> Assuming you are on a linux you could try: >>>> >>>> exec("find /the/path/to/the/place/where/you/should/start/searching -type >>> f >>>> -name 515515515*.ext", $files); >>>> >>>> Then the $files will be an array with the found files matching the >>> search. >>>> Best regards, >>>> Peter Lauri >>>> >>>> www.dwsasia.com - company web site >>>> www.lauri.se - personal web site >>>> www.carbonfree.org.uk - become Carbon Free >>>> >>>> -- >>>> PHP General Mailing List (http://www.php.net/) >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
;) Point taken! "; } ?> :) Thanks ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² On 3/29/07 4:58 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > DON'T commit suicide mate :) > > What if you one day move the path? ;) > > >> -Original Message- >> From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] >> Sent: Thursday, March 29, 2007 9:54 PM >> To: Peter Lauri; PHP >> Subject: Re: [PHP] Show Filename using Wildcards >> >> Ave, >> >> This Works!! >> >> > exec("find /Users/rjohari/Documents/XFER/espi -type f -name >> ".$row['PHONE']."*.vox", $files); >> foreach ($files as $value) { >> echo substr($value,35).""; >> } >> ?> >> >> THANKS! >> >> ~~~ >> Rahul Sitaram Johari >> CEO, Twenty Four Seventy Nine Inc. >> >> W: http://www.rahulsjohari.com >> E: [EMAIL PROTECTED] >> >> ³I morti non sono piu soli ... The dead are no longer lonely² >> >> >> >> On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: >> >> >>> [Peter Lauri - DWS Asia] >>> >>> Hi, >>> >>> Assuming you are on a linux you could try: >>> >>> exec("find /the/path/to/the/place/where/you/should/start/searching -type >> f >>> -name 515515515*.ext", $files); >>> >>> Then the $files will be an array with the found files matching the >> search. >>> >>> Best regards, >>> Peter Lauri >>> >>> www.dwsasia.com - company web site >>> www.lauri.se - personal web site >>> www.carbonfree.org.uk - become Carbon Free >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
Re: [PHP] Show Filename using Wildcards
Agreed! And definitely modified my code to use basename() "; } ?> Thanks! On 3/29/07 3:58 PM, "Tijnema !" <[EMAIL PROTECTED]> wrote: > On 3/29/07, Rahul Sitaram Johari <[EMAIL PROTECTED]> wrote: >> Ave, >> >> This Works!! >> >>>exec("find /Users/rjohari/Documents/XFER/espi -type f -name >> ".$row['PHONE']."*.vox", $files); >>foreach ($files as $value) { >>echo substr($value,35).""; >>} >>?> >> >> THANKS! > > I recommend using basename($value) instead of substr($value,35) > If the directory changes, the basename would still return valid > values, while substr wouldn't > > Tijnema >> >> ~~~ >> Rahul Sitaram Johari >> CEO, Twenty Four Seventy Nine Inc. >> >> W: http://www.rahulsjohari.com >> E: [EMAIL PROTECTED] >> >> ³I morti non sono piu soli ... The dead are no longer lonely² >> >> >> >> On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: >> >> >>> [Peter Lauri - DWS Asia] >>> >>> Hi, >>> >>> Assuming you are on a linux you could try: >>> >>> exec("find /the/path/to/the/place/where/you/should/start/searching -type f >>> -name 515515515*.ext", $files); >>> >>> Then the $files will be an array with the found files matching the search. >>> >>> Best regards, >>> Peter Lauri >>> >>> www.dwsasia.com - company web site >>> www.lauri.se - personal web site >>> www.carbonfree.org.uk - become Carbon Free >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >>
Re: [PHP] Show Filename using Wildcards
Awesome!! This Works!! "; } ?> THANKS! ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] “I morti non sono piu soli ... The dead are no longer lonely” On 3/29/07 3:52 PM, "Ben Roberts" <[EMAIL PROTECTED]> wrote: > Rahul Sitaram Johari wrote: > >> So I have to accomplish two things: >> >> 1. I have to eliminate the filepath from the result >> 2. I need to specify the variable that holds the phone number, (like >> $row[ŒPHONE¹]) instead of the actual phone number in the ³exec² command. >> >> Thanks!! Much Appreciated! >> > > To get the filename component without the path, just use the basename() > function: > > $file = basename($path); > > Ben
RE: [PHP] Show Filename using Wildcards
DON'T commit suicide mate :) What if you one day move the path? ;) > -Original Message- > From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 29, 2007 9:54 PM > To: Peter Lauri; PHP > Subject: Re: [PHP] Show Filename using Wildcards > > Ave, > > This Works!! > > exec("find /Users/rjohari/Documents/XFER/espi -type f -name > ".$row['PHONE']."*.vox", $files); > foreach ($files as $value) { > echo substr($value,35).""; > } > ?> > > THANKS! > > ~~~ > Rahul Sitaram Johari > CEO, Twenty Four Seventy Nine Inc. > > W: http://www.rahulsjohari.com > E: [EMAIL PROTECTED] > > ³I morti non sono piu soli ... The dead are no longer lonely² > > > > On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > > > > [Peter Lauri - DWS Asia] > > > > Hi, > > > > Assuming you are on a linux you could try: > > > > exec("find /the/path/to/the/place/where/you/should/start/searching -type > f > > -name 515515515*.ext", $files); > > > > Then the $files will be an array with the found files matching the > search. > > > > Best regards, > > Peter Lauri > > > > www.dwsasia.com - company web site > > www.lauri.se - personal web site > > www.carbonfree.org.uk - become Carbon Free > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
On 3/29/07, Rahul Sitaram Johari <[EMAIL PROTECTED]> wrote: Ave, This Works!! "; } ?> THANKS! I recommend using basename($value) instead of substr($value,35) If the directory changes, the basename would still return valid values, while substr wouldn't Tijnema ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > [Peter Lauri - DWS Asia] > > Hi, > > Assuming you are on a linux you could try: > > exec("find /the/path/to/the/place/where/you/should/start/searching -type f > -name 515515515*.ext", $files); > > Then the $files will be an array with the found files matching the search. > > Best regards, > Peter Lauri > > www.dwsasia.com - company web site > www.lauri.se - personal web site > www.carbonfree.org.uk - become Carbon Free > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Show Filename using Wildcards
Just do something like: $fileswithoutdir = array(); foreach($files AS $file) { $fileswithoutdir[] = basename($file); } Voila... Or you could do it more complicated in the foreach loop (but not recommended): $fileswithoutdir[] = preg_replace("/^.*\/(\d+\.vox)$/", "$1", $file); /Peter > -Original Message- > From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 29, 2007 9:49 PM > To: Peter Lauri; PHP > Subject: Re: [PHP] Show Filename using Wildcards > > > Peter, > > Believe it or not, but this is actually working. I'm on a Mac OS X, which > is > linux underneath, so I was hopeful about the command you provided. I ran > this code: > > exec("find /Users/rjohari/Documents/XFER/espi/ -type f -name > 33*.vox", $files); > foreach ($files as $value) { > echo "$value"; > } > > And it listed all the files that began with that provided phone number. > The only problem is, It¹s printing out the path with it too. So what¹s is > giving me is: > > /Users/rjohari/Documents/XFER/espi/331123.vox > /Users/rjohari/Documents/XFER/espi/334567.vox > > So I have to accomplish two things: > > 1. I have to eliminate the filepath from the result > 2. I need to specify the variable that holds the phone number, (like > $row[ŒPHONE¹]) instead of the actual phone number in the ³exec² command. > > Thanks!! Much Appreciated! > > ~~~ > Rahul Sitaram Johari > CEO, Twenty Four Seventy Nine Inc. > > W: http://www.rahulsjohari.com > E: [EMAIL PROTECTED] > > ³I morti non sono piu soli ... The dead are no longer lonely² > > > On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > > >> -Original Message- > >> From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] > >> Sent: Thursday, March 29, 2007 9:12 PM > >> To: PHP > >> Subject: [PHP] Show Filename using Wildcards > >> > >> Ave, > >> > >> I have a script where I have to provide a Download Link to a file > >> associated > >> with a record. The common thing between the record & filename is the > phone > >> number. But the filenames have dates & other symbols besides the phone > >> number as well. They all do begin with a phone number though. > >> > >> How can I match a filename with a record using wildcards? > >> For example, let¹s say someone pulls up a record for phone field: > >> 515515515 > >> The files associated with this record could be 515515515031307 or > >> 5155155150325T(2). > >> > >> So you can see the filenames do begin the phone number in the record, > but > >> they contain additional chars. What I need is something that can pull > up > >> all > >> 515515515*.ext > >> > >> Can I do this in PHP? > >> > >> Thanks! > >> > > > > [Peter Lauri - DWS Asia] > > > > Hi, > > > > Assuming you are on a linux you could try: > > > > exec("find /the/path/to/the/place/where/you/should/start/searching -type > f > > -name 515515515*.ext", $files); > > > > Then the $files will be an array with the found files matching the > search. > > > > Best regards, > > Peter Lauri > > > > www.dwsasia.com - company web site > > www.lauri.se - personal web site > > www.carbonfree.org.uk - become Carbon Free > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
Ave, This Works!! "; } ?> THANKS! ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: > [Peter Lauri - DWS Asia] > > Hi, > > Assuming you are on a linux you could try: > > exec("find /the/path/to/the/place/where/you/should/start/searching -type f > -name 515515515*.ext", $files); > > Then the $files will be an array with the found files matching the search. > > Best regards, > Peter Lauri > > www.dwsasia.com - company web site > www.lauri.se - personal web site > www.carbonfree.org.uk - become Carbon Free > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
Re: [PHP] Show Filename using Wildcards
Rahul Sitaram Johari wrote: So I have to accomplish two things: 1. I have to eliminate the filepath from the result 2. I need to specify the variable that holds the phone number, (like $row[ŒPHONE¹]) instead of the actual phone number in the ³exec² command. Thanks!! Much Appreciated! To get the filename component without the path, just use the basename() function: $file = basename($path); Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
Peter, Believe it or not, but this is actually working. I'm on a Mac OS X, which is linux underneath, so I was hopeful about the command you provided. I ran this code: exec("find /Users/rjohari/Documents/XFER/espi/ -type f -name 33*.vox", $files); foreach ($files as $value) { echo "$value"; } And it listed all the files that began with that provided phone number. The only problem is, It¹s printing out the path with it too. So what¹s is giving me is: /Users/rjohari/Documents/XFER/espi/331123.vox /Users/rjohari/Documents/XFER/espi/334567.vox So I have to accomplish two things: 1. I have to eliminate the filepath from the result 2. I need to specify the variable that holds the phone number, (like $row[PHONE¹]) instead of the actual phone number in the ³exec² command. Thanks!! Much Appreciated! ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² On 3/29/07 4:31 PM, "Peter Lauri" <[EMAIL PROTECTED]> wrote: >> -Original Message- >> From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] >> Sent: Thursday, March 29, 2007 9:12 PM >> To: PHP >> Subject: [PHP] Show Filename using Wildcards >> >> Ave, >> >> I have a script where I have to provide a Download Link to a file >> associated >> with a record. The common thing between the record & filename is the phone >> number. But the filenames have dates & other symbols besides the phone >> number as well. They all do begin with a phone number though. >> >> How can I match a filename with a record using wildcards? >> For example, let¹s say someone pulls up a record for phone field: >> 515515515 >> The files associated with this record could be 515515515031307 or >> 5155155150325T(2). >> >> So you can see the filenames do begin the phone number in the record, but >> they contain additional chars. What I need is something that can pull up >> all >> 515515515*.ext >> >> Can I do this in PHP? >> >> Thanks! >> > > [Peter Lauri - DWS Asia] > > Hi, > > Assuming you are on a linux you could try: > > exec("find /the/path/to/the/place/where/you/should/start/searching -type f > -name 515515515*.ext", $files); > > Then the $files will be an array with the found files matching the search. > > Best regards, > Peter Lauri > > www.dwsasia.com - company web site > www.lauri.se - personal web site > www.carbonfree.org.uk - become Carbon Free > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
Re: [PHP] Show Filename using Wildcards
Rahul Sitaram Johari wrote: Ave, Yes well, I did kind of figure out that I have to scan through contents of a directory, pull up a file list, and then do some kind of pattern matching to narrow down to the files I need. But at this moment I'm kinda struggling with the directory & file functions - haven't really dwelled into those deeply before. Good place to start: http://www.php.net/manual/en/function.opendir.php Some good examples on getting contents of a directory... -B But yes, your suggestions seem more then likely what I'll be hitting at some stage. Thanks. On 3/29/07 3:22 PM, "Brad Bonkoski" <[EMAIL PROTECTED]> wrote: I'm sure there are many options... I'm also assuming you are pulling from a file system and not a database... So, loop through the directory and do something like this: $phone_num = XXX $cur_file = xxx if( strncmp($phone_num, $cur_file, strlen($phone_num)) == 0 ) //Matches else //No Match Ref: http://us3.php.net/manual/en/function.strncmp.php (for case insensitive: http://us3.php.net/manual/en/function.strncasecmp.php) -B -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
Ave, Yes well, I did kind of figure out that I have to scan through contents of a directory, pull up a file list, and then do some kind of pattern matching to narrow down to the files I need. But at this moment I'm kinda struggling with the directory & file functions - haven't really dwelled into those deeply before. But yes, your suggestions seem more then likely what I'll be hitting at some stage. Thanks. On 3/29/07 3:22 PM, "Brad Bonkoski" <[EMAIL PROTECTED]> wrote: > I'm sure there are many options... > I'm also assuming you are pulling from a file system and not a database... > So, loop through the directory and do something like this: > $phone_num = XXX > $cur_file = xxx > if( strncmp($phone_num, $cur_file, strlen($phone_num)) == 0 ) > //Matches > else > //No Match > > Ref: http://us3.php.net/manual/en/function.strncmp.php > (for case insensitive: > http://us3.php.net/manual/en/function.strncasecmp.php) > -B -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Show Filename using Wildcards
> -Original Message- > From: Rahul Sitaram Johari [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 29, 2007 9:12 PM > To: PHP > Subject: [PHP] Show Filename using Wildcards > > Ave, > > I have a script where I have to provide a Download Link to a file > associated > with a record. The common thing between the record & filename is the phone > number. But the filenames have dates & other symbols besides the phone > number as well. They all do begin with a phone number though. > > How can I match a filename with a record using wildcards? > For example, let¹s say someone pulls up a record for phone field: > 515515515 > The files associated with this record could be 515515515031307 or > 5155155150325T(2). > > So you can see the filenames do begin the phone number in the record, but > they contain additional chars. What I need is something that can pull up > all > 515515515*.ext > > Can I do this in PHP? > > Thanks! > [Peter Lauri - DWS Asia] Hi, Assuming you are on a linux you could try: exec("find /the/path/to/the/place/where/you/should/start/searching -type f -name 515515515*.ext", $files); Then the $files will be an array with the found files matching the search. Best regards, Peter Lauri www.dwsasia.com - company web site www.lauri.se - personal web site www.carbonfree.org.uk - become Carbon Free -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
Rahul Sitaram Johari wrote: Ave, I have a script where I have to provide a Download Link to a file associated with a record. The common thing between the record & filename is the phone number. But the filenames have dates & other symbols besides the phone number as well. They all do begin with a phone number though. How can I match a filename with a record using wildcards? For example, let¹s say someone pulls up a record for phone field: 515515515 The files associated with this record could be 515515515031307 or 5155155150325T(2). So you can see the filenames do begin the phone number in the record, but they contain additional chars. What I need is something that can pull up all 515515515*.ext Can I do this in PHP? I'm sure there are many options... I'm also assuming you are pulling from a file system and not a database... So, loop through the directory and do something like this: $phone_num = XXX $cur_file = xxx if( strncmp($phone_num, $cur_file, strlen($phone_num)) == 0 ) //Matches else //No Match Ref: http://us3.php.net/manual/en/function.strncmp.php (for case insensitive: http://us3.php.net/manual/en/function.strncasecmp.php) -B Thanks! ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php