473,809 Members | 2,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3717
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_TRANSLATE D']);
$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_TRANSLATE D']);
$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
21306
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. http://validator.w3.org/check?uri=http://www-thaihydro.geog.cam.ac.uk/riverslice/&ss=1&verbose=1 (e.g. see line 77) suggests that it is valid, but the spec suggests that it is not. More detail:
5
6252
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 build folder named images.
1
8766
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 : hghghg/hgjhgh/ghfgg/gfgf/product76-x3/image1.jpg What I require is to place 'product76-x3' in one variable and image1.jpg in a second, in order for me to create a new string URL.
8
6337
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 control under the App_Code folder, how can i add a register tag on a page. <%@ Register TagPrefix="ABC" Namespace="ABC.Foo" Assembly="???????????????" %> My other question is "Since i don't know the name of the assembly of the
7
1559
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: <form name="Visual" method="post" action="Salesreport.aspx?Index=7" language="javascript" onsubmit="javascript:return WebForm_OnSubmit();" id="Visual">
4
4455
by: Magnus Warker | last post by:
Hello group, I am producing a form within a table: <table> <tr> <td> <form> ... </form>
8
3226
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 box. I delete this program but it still show in the box ( like Antivirous or Media playre) Now I want to remove this kind of item in this menu box . Is it possible. Because those is getting longer.
1
2213
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>, faulting module <module name>, version <version number>, fault address <hex address>. Under what scenario does the above error occurs?
3
1357
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 gives this result: 294643) can anyone help to fixt it becasue i need only the figures. Private Sub Toggle2_Click()
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.