php - Exploding path foldernames and storing it in an array -
i have filepath:
/www/htdocs/nether/http/helloworld/application/views/scripts/index/dashboard-stats.phtml
what want store helloworld folder in array element. in example helloworld foldername on 5 place. when placing on different webserver on second or thrid place. how automatically?
i have code works,see below.
$pieces = explode($_server["document_root"], __file__); $parts = explode("/", $pieces[1]); echo $parts[1];
my question is, besides doing automatically, possible in less 3 lines of code?
if you're using php 5.4.0 following:
echo explode("/",explode($_server["document_root"], __file__)[1])[1];
however i'd prefer original version since it's easier read , can check resulting arrays make sure have @ least 2 elements.
Comments
Post a Comment