SSupreme
asked on
URL directory echo
I need extract few directories from URL except first one if length = 2, for example:
experts-exchange.com/WD/Web_Languages-Standards/P HP/newQuestionWizard.jsp
I need to only bold part and ignore first directory as it's length equal 2;
experts-exchange.com/Web_Development/Web_Langu ages-Stand ards/PH/newQuestionWizard.jsp
I need all directories as first one isn't equal 2, and it doesn't matter what length of others.
experts-exchange.com/WD/Web_Languages-Standards/P
I need to only bold part and ignore first directory as it's length equal 2;
experts-exchange.com/Web_Development/Web_Langu
I need all directories as first one isn't equal 2, and it doesn't matter what length of others.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excuse me, which scheme?
ASKER
ok it works 100%, I guess it was easy for you, so could you please suggest how to show name of directory if it's first and length = 2.
ASKER
You are Genius Indeed, thanks
so could you please suggest how to show name of directory if it's first and length = 2.If I understand your question correctly, then I believe what you could do would be to change the second preg_replace to:
preg_match('#^(/?[^/]{2}(?=/))?(.*)$#', $result, $matches); // Remove first dir if it's 2 characters
You would have the 2-character directory (or empty string) in the second index of $matches, and you would have the remaining directories in the third index. In other words:
var_dump($matches[1]); // 2-character directory (or empty string)
var_dump($matches[2]); // Remaining directories
ASKER
Please reply here:
https://www.experts-exchange.com/questions/27405546/URL-directory-echo2.html
https://www.experts-exchange.com/questions/27405546/URL-directory-echo2.html
Open in new window