I have this bit of PHP code which strips -
the dash from the incoming string. The array key may or may not have a -
between each word. So if the string has spaces or dashes, the string is still matched to the key.
Now I need to expand this a little to have a partial match locate the key in the array.
Here's what I have so far.
My array
$pages = array(
'Administrator' => array(
'network-administrator' => array('title' => 'Network '.$li_1, 'description' => 'Network '.$li_1.' '.$temp_content, 'post' => '<p>Network '.$li_1.' '.$temp_content.'.</p>'),
'database administrator' => array('title' => 'Database '.$li_1, 'description' => 'Database '.$li_1.' '.$temp_content, 'post' => '<p>Database '.$li_1.' '.$temp_content.'.</p>'),
),
'Analyst' => array(
'business systems analyst' => array('title' => 'Business Systems '.$li_2, 'description' => 'Business Systems '.$li_2.' '.$temp_content, 'post' => '<p>Business Systems '.$li_2.' '.$temp_content.'.</p>'),
'data-analyst' => array('title' => 'Data '.$li_2, 'description' => 'Data '.$li_2.' '.$temp_content, 'post' => '<p>Data '.$li_2.' '.$temp_content.'.</p>'),
),
);
PHP foreach loop
$t_keys = array();
foreach ($pages as $k => $arr2) {
foreach (array_keys($arr2) as $a) {
$new_key = str_replace("-", " ", $a);
$t_keys[$new_key] = array( $k, $a );
}
}
$str = str_replace(array('-', ' and '), ' ', strtolower($position));
if (array_key_exists($str, $t_keys)) {
$target = $pages[ $t_keys[$str][0] ][ $t_keys[$str][1] ];
}
$t_keys[$str][0]
accesses the key Administrator
and $t_keys[$str][1]
accesses sub-key network-administrator
.
What I need to do is match incoming strings from the query string in the URL to find matches in the sub-keys of the array.
Example partial match strings that are coming in are oracle database administrator
. That key is not in my array, but oracle administrator
is, as well as database administrator
.
So how could I match strings coming in to the sub-keys in the array if similar words exist?
Here is a small list of incoming partial match strings coming in my error log.
it
apple
css
.net developer
desktop
.net
python
apple
data center
phone technician
sql database developer
jquery
delphi
css
python
pc
software
xml
webmaster
research development
python programming
computer technician or pc technician
.net
c
in some cases, the above partial matches don't exist anywhere in the array. I am just doing a redirect on those. But others such as data center
and python programming
just as an example are in the array.
Example for the string data center
, the nearest match in the array would be data center technician
and the nearest match for string python programming
would be python developer
.
All help appreciated!
EDIT
Just to be clear, here is some more info about partial matching that will be an issue.
yes I know that some matches will be more trickier than others. In my array, there is no key called programming
but there is a key called developer
so string python programming
could be placed to sub key python developer
as that is a sub key of the developer key.
Others such as the string data center
it will be trickier because there are several sub keys of main keys that have the word data center
.
Let's take for example the string computer technician or pc technician
. That is no longer a sub-key in my array. but there are sub keys called computer technician
as well as pc technician
. Which one to partial match if both sub keys exist in the string?
If I can get something basic for now that will atleast take care of some of these partial matches, then I'm on the right track.
EDIT 2
Here's another example of a string business analyst
. There is a sub key in my array called business systems analyst
. The word business
and analyst
are both words in the sub key. So I need to create something that I can continue to add onto every time a new string comes in that isn't matching properly in the array.
EDIT 3
After thinking for a few minutes, I think the best way will be to manually add each partial string that comes in to an array and reference those to the sub key of my choosing.
oes that make sense?
So I need to create a php snippet that I keep adding to the array container of partial match strings that point to the key in the array. How can I do that?