Forum Moderators: coopster
$string = "$REQUEST_URI";
$pattern = '^.*/([^\./]*)\..{3,4}$';
eregi($pattern, $string, $vars);
echo $vars[1];
Ok, just to go a step further on this, I'm using apache and have heard the wonders of mod_rewrite, and I wonder if it can be used here for some neato reason ;)
The URL used above will be a plain old number, no query string...just grabbing the number of the file. This number will match a word in a db.....is there a surefire way of converting the number into the word related to it in the db? I think mod_rewrite is the answer here, I'm new to apache and wouldnt know where to start apart from inklings from old threads.
This leaves me a bit confused, if Andreas' method is more efficient then how do I get it to do what jatars code done for me first time off ....if anyone knows, I'd be thankful for covering up my ignorance of PHP :)
/added that was with replacing $url, with $request_uri.......seems efficiency is the least of my probs before i get to understand the code better
$matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
preg_match [php.net]
$url = "http://www.something.com/dir1/111.htm";
preg_match("'/(\d+)\.[a-z]{3,4}$'i", $url, $matches);
$number = $matches[1];
Andreas
I too need the same sort of effect. I'm using an include for my navigation with a call to a db so I can change my menu site wite at once(I love this php/mysql stuff).
Now I'd like to go a step further, and run an if/else on the results so I can match the current page and deactivate the link to the current page.
I'm using this to get the url:
$filelocation=$HTTP_HOST.$PHP_SELF;
echo($filelocation);
What I get from that is:
www.my_site.com/the_page I'm_on.html
I need to cut the actual filename off of the url or is there a way to call for the filename itself?
Thanks
I know there is one for the file on its own, just cant find it...no doubt someone else will post it.
You might also want to use parse_url, which breaks up a URL into fragments. You could use all the fragments of the URL after the host.
I found this on this page
[php.net...]