Laserlight, Thanks for pointing me in the right direction. I've been working on this script based on your post for a few weeks and now I'm 98% there. Just one more road bump 🙂!
I have a string that will sometimes contain one word, and sometimes contain more then one. Now the trick here is, that the string is a directory path, and I need to extract the last part (the folder name).
So:
/user/docs/client1
a new $var needs to hold the value client1
/user/docs/some new client
a new $var needs to hold the value some new client - while keeping the spaces in the string
I'm using a reg expression generator to strip out the first part of the URL, because I just need the last directory in the path. That's working fine but only extracts on word:
$location = "/user/docs/some new client"
$re1='.*?'; # Non-greedy match on filler
$re2='(?:[a-z][a-z0-9_]*)'; # Uninteresting: var
$re3='.*?'; # Non-greedy match on filler
$re4='(?:[a-z][a-z0-9_]*)'; # Uninteresting: var
$re5='.*?'; # Non-greedy match on filler
$re6='((?:[a-z][a-z0-9_]*))'; # Variable Name 1
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $location, $matches))
{
$var1=$matches[1][0];
print $var;
}
The problem is this code only extracts the word 'client'. ($var = "some"😉
I tried this code:
$location = str_replace(' ', '', $location);
Which runs multiple words together. That sort of solves the problem but I need to have those spaces in there for another part of the script to work.
Can you suggest what I might do? Thanks for your help.
Regards,
Matt