473,236 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

Remove from $name (folder)/(folder)/[x]/ <-- if exists to just get [x].

Guys and girls, I'll be quite honest. I don't have the faintest idea
how to do this, while I can do other php without a problem. Once I
know how to go about it I'll be okay.
It's two things I think?
1. see if there's a trailing slash and delete it.
2. Remove the preceding path to /x, the folders and slashes, and
delete them.
and then I have x.

X by the way is the final folder in a website and this grabs it for
me.

<?
$name = $REQUEST_URI;
?>

Any help would be greatly appreciated.
Thanks !!!!!!!!!!!!!!!!!!!
Jul 16 '05 #1
5 3699
On Tue, 05 Aug 2003 20:46:37 -0700, george wrote:
Guys and girls, I'll be quite honest. I don't have the faintest idea how
to do this, while I can do other php without a problem. Once I know how to
go about it I'll be okay. It's two things I think?
1. see if there's a trailing slash and delete it. 2. Remove the preceding
path to /x, the folders and slashes, and delete them.
and then I have x.

X by the way is the final folder in a website and this grabs it for me.

<?
$name = $REQUEST_URI;
?>

Any help would be greatly appreciated. Thanks !!!!!!!!!!!!!!!!!!!


Warning! Untested code follows...
<?php

// Make sure path ends in no slash (optional step you are *certain* that
// the URL will or will not end in a slash):
$request_uri = preg_replace("/\/*$/", "", $REQUEST_URI);

// Split the path into an array:
$path_array = split("/", $REQUEST_URI);

// pop off the end:
$x = array_pop($path_array);

echo "The URL ends in $x\n";
?>

later...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #2
Jeffrey Silverman wrote:

<big snip>
On second thought, maybe i *should* have used $REQUEST_URI! Other than
that, I'm not sure what the trouble is...


REQUEST_URI tends to be a good choice, if you're using URL rewriting...
Jul 16 '05 #3
On Thu, 07 Aug 2003 16:09:24 -0700, george wrote:
Hi Jeffrey.
Hmm.
No, this again gives me the originating page, not the folder that it's in,
ie, test.php, rather than [x].
*grin*


do array_pop() twice, then:
<?
$path = preg_replace("/^\/|\/$/", "", $_SERVER['PATH_TRANSLATED']);
$path_array = split("/", $path);
array_pop($path_array);
$page_name = array_pop($path_array);
?>

My questions to you are:
* What does the REQUEST_URI look like?
i.e. is it a directory (ends in a slash) or a file? The original code I
gave works if the URI ends in the *directory* name, not a file name!
* Do you understand the logic of the above code? What is it that I am
doing?

I'll explain in English what each line does. I find that for complex tasks
it is often best to speak out loud the steps or write them down as
sentences -- English sentences, not code sentences. Then convert English
logic to code logic. So, here goes:

1) Get URI; *assume* URI is a directory.
2) See if URI ends in a slash, if so, we want to get rid of it.
3) make a list of all the elements in the URI where the element delimeter
is the slash (/) character.
4) get the last item in the list.

Number 4 is the part that really assumes that the URI is a *directory* and
not a file! If the URI ends in a file name, number 4 shuold read "Take the
second-to-last item in the list"

Good luck!
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #4
Jeffrey Silverman wrote:

I'll explain in English what each line does. I find that for complex tasks
it is often best to speak out loud the steps or write them down as
sentences -- English sentences, not code sentences. Then convert English
logic to code logic. So, here goes:

1) Get URI; *assume* URI is a directory.
2) See if URI ends in a slash, if so, we want to get rid of it.
3) make a list of all the elements in the URI where the element delimeter
is the slash (/) character.
4) get the last item in the list.

Number 4 is the part that really assumes that the URI is a *directory* and
not a file! If the URI ends in a file name, number 4 shuold read "Take the
second-to-last item in the list"

Good luck!

Hence the regex solution...

Jul 16 '05 #5
I'm very embarassed, as well as being thankful.
On my 1st read of your reply I didn't see *new* php.

It works a treat, from any folder.

<?
$path = preg_replace("/^\/|\/$/", "", $_SERVER['PATH_TRANSLATED']);
$path_array = split("/", $path);
array_pop($path_array);
$page_name = array_pop($path_array);
echo $page_name;
?>

Thanksalot
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Martin Lucas-Smith | last post by:
I am wanting to know whether are XHTML1-valid characters for use within an id attribute and/or a name attribute. ...
5
by: Lucas Ponzo | last post by:
I have the following directory structure: \images \other_images\images There is duplicate names, but at diferent levels. But the Visual Studio Setup Project emits the error: Unable to...
1
by: davidgordon | last post by:
Hi, I'm using the FileOpenDialog API that everyone has told me about which is posted everywhere on this forum.....works like a dream. When I select a file I get the full path such as : ...
8
by: Umut Tezduyar | last post by:
I know that, in asp.net 2.0, the assembly for the web site is splitted into pieces and each time you build it, it generates a random name for assembly. My question is, if i create a custom web...
7
by: Mike Owen | last post by:
I have a vb.net page that uses a form as below: <form id="Visual" name="Visual" method="post" runat="server"> If I run this on my Windows XP development PC then the HTML generated from it is:...
4
by: Magnus Warker | last post by:
Hello group, I am producing a form within a table: <table> <tr> <td> <form> ... </form>
8
monirul arfin
by: monirul arfin | last post by:
Hi all, when we right click on a folder, a menu box is open , where is show " Open, Explore, Search, Send to, Cut, Copy etc" . And if we install a program , this program item will be shown in this...
1
by: Nilam2477 | last post by:
I have application developed in VC/COM/DCOM At some point of time i got the following error message and application closed. Faulting application <application name>, version <version number>,...
3
by: ahd2008 | last post by:
HI, I created the code below to remove name from tex. For instance, a field contains Caffery(294643) so i want to get rid of Caffery and get only the figures, but the problme that the code...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.