473,626 Members | 3,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with string replace...

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!
Jul 17 '05 #1
7 2764
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.dirnam e.php>

Regards.

Guillaume
Jul 17 '05 #2
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.dirnam e.php>

Regards.

Guillaume
Jul 17 '05 #3


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

Jul 17 '05 #4
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 =--
Jul 17 '05 #5
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
Jul 17 '05 #6
> 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!
Jul 17 '05 #7
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!
Jul 17 '05 #8

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

Similar topics

8
2064
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 make the ESC key quit the called function when ever the user inputs data. The description was : ESC drops back to the main menu in case the user gets locked up or wants to start over again, ESC should provide a fool proof way to exit back to the...
4
308
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 // replaced with user's code for getting in string value. var sInputString = 'asp and database'; sText = sInputString;
5
11342
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 variable on which I need to perform log and then divide the result with 3.980. While parsing such expressions, I need to find all occurence of date values and replace "/" character with "~" character. I need to do this only for date portion of the
1
3703
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
22
2177
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 grabbed, BUT it doesn't. I have tried and tried.....please help example: C:\Projects\Darryl\Queue Review Files\2-24\Cam 7\Cam7-20060224170000-01.jpg Cam7 but all I keep getting is Cam1, as the beginning of the jpg name,...:( HELP!
1
2012
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 help is appreciated .. Jim
31
4578
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 are more objects that match the first object that i grabbed. If they match then I put them in an array. I would like to remove each match from the arraylist as I find them to speed things up and so that they don't get checked again. If I try...
2
2362
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 following: Search a whole blob of text (including newlines and everything). Find any text enclosed in brackets (), and replace it with a string I provide and then concatenate the text that had been enclosed in the brakets, without the brakets.
4
2787
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 find a chosen substring lets say "cat" and then replace it with a difrent inputed substring say "dog". Tried to get as far as i could on my own but need some help, sugestions, snippets or guidence. # include<stdio.h> # include<math.h> #...
5
4932
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8266
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
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
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
8638
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
8365
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
8505
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
5574
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
4092
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...
2
1511
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.