473,387 Members | 3,787 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,387 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 3702
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.