hi all
i want to get the name of the file that i'm currently working with. i have an idea to get $_SERVER['PHP_SELF'] and then break up the text string to do that. If i get the string /kompetencesystem/default.php i need to get the default.php part from it.
Now my question is:
Is this the simplest way to do it? and if it is how is this achieved?
any hints will be useful thx
regards
thallish
[SOLVED]breaking up text
Moderator: General Moderators
[SOLVED]breaking up text
Last edited by thallish on Sun Jun 12, 2005 7:21 am, edited 1 time in total.
OK i solved it already
here is what i did
Now does this look reasonable?
thallish
here is what i did
Code: Select all
$site = $_SERVER['PHP_SELF'];
$array = explode('/', $site);
$array = array_reverse($array);
$site = $array[0];thallish
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
It sure does, but obviously, me being me will have to jump in and do a regex 
Your way does the job, my way is just typically my regex way 
Code: Select all
$this_file = $_SERVER['PHP_SELF']; # /app1/classes/classname.class.php
$this_file = preg_replace('#([^/]+)$#', '$1', $this_file); # classname.class.php- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
d11, regex may be extremely useful and all, but a lot of the times it can really slow down page execution time. I thought this would be a perfect example to run a quick benchmark.
I ran both sets of codes, yours and thallish, 10 000 times in a loop to get an semi-accurate average.
Results:
Thallish: Execution took on average (0.015681743621826) Seconds
d11wtq: Execution took on average (0.030075311660767) Seconds
Conclusion: Regex may not always be the best solution, althought I salute your cunningness.
I ran both sets of codes, yours and thallish, 10 000 times in a loop to get an semi-accurate average.
Results:
Thallish: Execution took on average (0.015681743621826) Seconds
d11wtq: Execution took on average (0.030075311660767) Seconds
Conclusion: Regex may not always be the best solution, althought I salute your cunningness.