473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parsing a string for keywords

I need to parse a set of directory entries (of photo image files)
and pull out the names of the subjects, which is in the filename.

A file name could contain 1 or more subject names from a limited
set of 18 possibilities.

eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....

the file name might be: 0709-Aoife-Alana-DSC12435.jpg

I could do 18 stripos() calls to check for all 18 possibilities,
but I thought I would run it by the more experienced to see if
you can suggest an easier way

thanks in advance.

bill
Jan 27 '07 #1
5 1464
Rik
bill <no****@spamcop.netwrote:
I need to parse a set of directory entries (of photo image files) and
pull out the names of the subjects, which is in the filename.

A file name could contain 1 or more subject names from a limited set of
18 possibilities.

eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....

the file name might be: 0709-Aoife-Alana-DSC12435.jpg

I could do 18 stripos() calls to check for all 18 possibilities, but I
thought I would run it by the more experienced to see if you can suggest
an easier way

thanks in advance.
$possibities = array('foo','bar','baz'........);
$filenameparts = explode('-',$filename);
$matches = array_intersect($filenameparts,$possibities);
--
Rik Wasmus
Jan 27 '07 #2
Rik wrote:
bill <no****@spamcop.netwrote:
>I need to parse a set of directory entries (of photo image files) and
pull out the names of the subjects, which is in the filename.

A file name could contain 1 or more subject names from a limited set
of 18 possibilities.

eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....

the file name might be: 0709-Aoife-Alana-DSC12435.jpg

I could do 18 stripos() calls to check for all 18 possibilities, but I
thought I would run it by the more experienced to see if you can
suggest an easier way

thanks in advance.

$possibities = array('foo','bar','baz'........);
$filenameparts = explode('-',$filename);
$matches = array_intersect($filenameparts,$possibities);
--Rik Wasmus
absolutely lovely

bill
Jan 27 '07 #3
Rik
bill <no****@spamcop.netwrote:
Rik wrote:
>bill <no****@spamcop.netwrote:
>>I need to parse a set of directory entries (of photo image files) and
pull out the names of the subjects, which is in the filename.

A file name could contain 1 or more subject names from a limited set
of 18 possibilities.

eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....

the file name might be: 0709-Aoife-Alana-DSC12435.jpg

I could do 18 stripos() calls to check for all 18 possibilities, butI
thought I would run it by the more experienced to see if you can
suggest an easier way

thanks in advance.
$possibities = array('foo','bar','baz'........);
$filenameparts = explode('-',$filename);
$matches = array_intersect($filenameparts,$possibities);
Addendum, if you want a case-insensitive comparison (PHP >= 5):
$matches = array_uintersect($filenameparts,$possibities,'strc asecmp');

--
Rik Wasmus
Jan 27 '07 #4
Rik wrote:
bill <no****@spamcop.netwrote:
>Rik wrote:
>>bill <no****@spamcop.netwrote:

I need to parse a set of directory entries (of photo image files)
and pull out the names of the subjects, which is in the filename.

A file name could contain 1 or more subject names from a limited set
of 18 possibilities.

eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....

the file name might be: 0709-Aoife-Alana-DSC12435.jpg

I could do 18 stripos() calls to check for all 18 possibilities, but
I thought I would run it by the more experienced to see if you can
suggest an easier way

thanks in advance.
$possibities = array('foo','bar','baz'........);
$filenameparts = explode('-',$filename);
$matches = array_intersect($filenameparts,$possibities);

Addendum, if you want a case-insensitive comparison (PHP >= 5):
$matches = array_uintersect($filenameparts,$possibities,'strc asecmp');

--Rik Wasmus
thanks for the update, but my web host is still at 4.1.x

bill
Jan 28 '07 #5
On Jan 28, 12:28 pm, bill <nob...@spamcop.netwrote:
Rik wrote:
bill <nob...@spamcop.netwrote:
Rik wrote:
bill <nob...@spamcop.netwrote:
>>I need to parse a set of directory entries (of photo image files)
and pull out the names of the subjects, which is in the filename.
>>A file name could contain 1 or more subject names from a limited set
of 18 possibilities.
>>eg: the possibilities might be: Aoife, Alana, Liam, Paddy.....
>>the file name might be: 0709-Aoife-Alana-DSC12435.jpg
>>I could do 18 stripos() calls to check for all 18 possibilities, but
I thought I would run it by the more experienced to see if you can
suggest an easier way
>>thanks in advance.
$possibities = array('foo','bar','baz'........);
$filenameparts = explode('-',$filename);
$matches = array_intersect($filenameparts,$possibities);
Addendum, if you want a case-insensitive comparison (PHP >= 5):
$matches = array_uintersect($filenameparts,$possibities,'strc asecmp');
--Rik Wasmus

thanks for the update, but my web host is still at 4.1.x

bill
You could iterate through your arrays, changing the case of each
element to lower/higher, and then compare with array_intersect. If you
just put strtolower() around the second argument of explode, that
should take care of that array. You could use array_map for the
former.

--
Curtis

Jan 30 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: keith | last post by:
I am trying to build a where clause for mysql based on different form inputs but php seems to have a problem with the following: $whrClause = "WHERE keywords LIKE '%$keywords%'" I thought with...
1
by: abracad_1999 | last post by:
Before I write one, are there any free scripts out there that will take a string of text and output a list of spearate keywords?
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
2
by: Todd Moyer | last post by:
I would like to use Python to parse a *python-like* data description language. That is, it would have it's own keywords, but would have a syntax like Python. For instance: Ob1 ('A'): Ob2...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: Miguel Dias Moura | last post by:
Hello, I am calling an ASP.NET / VB as follows: search.aspx?search=asp%20book%20london Then I create a string with the keywords like this: Dim keywords() As String =...
14
by: Peter | last post by:
Could someone please point me to a function/module for Access 2000 that will enable me to parse a string field. So if a field consists of "word_1 word_2 ...... word_n", I would like to be able...
13
by: abcdefghijklmnop | last post by:
I have a "Questions" form that reads off of a table and contains a multi-value field called "Keywords". I already know that having a multi-value field is a horrible idea, however, I am patching up a...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
3
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.