Hello everyone!
I've got the problem with string replace,
i've got a string like:
/adsf/sdfd34/sdf/435ff/sdfdf
and i need to delete the last characters before "/", so it would
become:
/adsf/sdfd34/sdf/435ff/
I am trying to make a file manager of a sort, and need to make a link
"UP", which would take the user up one level in a directory...
I tried to use str_replace, seems its not the one,
thn i tried to use preg_replace, seems it is the one i need, but i'm
nowhere
near there...
Thats my last effort:
$output = preg_replace("/(\/*$)/","/", $input);
Could someone help me please?
Thank you very much! 7 2754
Tihon wrote: Hello everyone! I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory... I tried to use str_replace, seems its not the one, thn i tried to use preg_replace, seems it is the one i need, but i'm nowhere near there... Thats my last effort: $output = preg_replace("/(\/*$)/","/", $input); Could someone help me please? Thank you very much!
There is a nice function in the PHP function, section Filesystem, called
dirname. Look at <http://www.php.net/manual/en/function.dirname.php>
Regards.
Guillaume
Tihon wrote: Hello everyone! I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory... I tried to use str_replace, seems its not the one, thn i tried to use preg_replace, seems it is the one i need, but i'm nowhere near there... Thats my last effort: $output = preg_replace("/(\/*$)/","/", $input); Could someone help me please? Thank you very much!
There is a nice function called dirname in the PHP toolbox, under the
section Filsystem. It could repond to your needs.
See <http://www.php.net/manual/en/function.dirname.php>
Regards.
Guillaume Hello everyone! I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory...
I'm unclear why a simple "<a href="../"> won't work, instead of trying to
compute what the reference should be.
Martin
Tihon wrote: i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/
(snip)
Why not combine substr() and strrpos()? http://www.php.net/substr http://www.php.net/strrpos
$output = substr($input, 0, strrpos($input, '/'));
when $input is '/one/two'
strrpos($input, '/') will give the position of the last '/' in it (4 in
this case); substr() will return '/one'
Verify whether you need the last character to be a '/' and modify that
line accordingly.
Don't forget to check for inputs without '/'s.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Martin Lucas-Smith wrote: Hello everyone! I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory...
I'm unclear why a simple "<a href="../"> won't work, instead of trying to compute what the reference should be.
using mod_rewrite may be one good reason...
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Official Google SERPs SEO Competition: http://www.koivi.com/serps.php
> Tihon wrote: i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ (snip)
Why not combine substr() and strrpos()? http://www.php.net/substr http://www.php.net/strrpos
$output = substr($input, 0, strrpos($input, '/')); when $input is '/one/two'
strrpos($input, '/') will give the position of the last '/' in it (4 in this case); substr() will return '/one'
Verify whether you need the last character to be a '/' and modify that line accordingly.
Don't forget to check for inputs without '/'s.
Thanks all of you so very much!
Dirname does exactly what i need (never heard of it before, i
definately must get a book! :()
And combining substr and strrpos is a great way too!
Thanks a lot!
Pedro Graca <he****@hotpop.com> wrote in message news:<bv*************@ID-203069.news.uni-berlin.de>... Tihon wrote: i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ (snip)
Why not combine substr() and strrpos()? http://www.php.net/substr http://www.php.net/strrpos
$output = substr($input, 0, strrpos($input, '/')); when $input is '/one/two'
strrpos($input, '/') will give the position of the last '/' in it (4 in this case); substr() will return '/one'
Verify whether you need the last character to be a '/' and modify that line accordingly.
Don't forget to check for inputs without '/'s.
My previous post does not seem to appear,
Thanks to all of you, thats exactly what i needed!
Thank you! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Foxy Kav |
last post by:
Hi everyone, Im currently doing first year UNI, taking a programming
course in C++, for one project i have to create a simple array
manipulator... that i have done, but i cant figure out how to...
|
by: Andrew |
last post by:
I am a newbie to C# and would appreciate any help converting the
following javascript function to C#
function fxnParseIt() {
// Note: sInputString code for demo purposes only, and should be
// ...
|
by: Mahesha |
last post by:
Hello,
I need help in replacing one string pattern with another.
Ex: I have a financial security expression like
log(T 3.25 6/24/2004)/sqrt(T 4.5 6/19/2002)
Here "T 3.25 6/24/2004" is a...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: KitKat |
last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,
and Cam 8. Well it does that but it also needs to change the file name to
the same folder where the file is being...
| |
by: Random Task |
last post by:
Can someone help me by providing an example of how to replace / with \
in a string in xslt2.
The characters / and \ seem to cause me grief ...
I am trying the below code currently ...
Any...
|
by: Extremest |
last post by:
I have a loop that is set to run as long as the arraylist is > 0.
at the beginning of this loop I grab the first object and then
remove it. I then go into another loop that checks to see if there...
|
by: Alex Maghen |
last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone
really good with Regular Expressions can help me out here.
I need to write a regular expression that will do the...
|
by: sandvet03 |
last post by:
I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |