yes you are right the preg_replace will run only if the path doesnt has any forward slashes inside it or if it starts with a forward slash, but after i looked in the script i have found that they strip off (remove) preceding slash and also last slash from the path before they use this line of code.
this is how they remove the preceding and last slashes so it will never has a slash in the first character... :
so you are right the purpose of this line of code is to find the parent path/folder of the current file/folder and if it is found in the root (with no slashes inside it) it return an empty character....
the only thing i dont understand is how technically the mechanism of this regular expression work in this case ?!!
for example lets say $f = '/dir1/dir3/'
first the code strip off the first and last slashes
after that the code will return the parent path in $fp
so $fp = 'dir1/'
what i dont understand understand the sequence or logic of how the preg_replace work on this case 'dir1/dir3'
what this mean exactly #(.*/)[^/]*$#
how it work ?
what is done first (.*/) or [^/] ?
why they didnt used "or" "|" between the two ?
what i understand please correct me :
the preg_replace catch everything
So : 'dir1/dir3' = #(.*/)[^/]*$#
and replace it only with the capture group :
So (.*/) = 'dir1/' So $fp = 'dir1/'
but what i dont understand why they didnt used "or" "|"
like when they stripped off the first and last slashes.
thanks man you deserve a nice cup of beer...catch up