Re: Strings

From: Date: Tue, 12 Dec 2000 00:17:05 +0000
Subject: Re: Strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29776@lists.php.net to get a copy of this message
Previously, Brandon Orther said: > > I have a variable that uses "/" to separate words, and I want to take the > last word of the string of and return everything before it. Here are some > examples: > /usr/test/because ==> /usr/test/ > > /this/is/a/test ==> /this/is/a/ Something like this should work. I've got two different methods shown below, take your pick. <?php $a = '/usr/test/because'; $a = dirname($a); print "$a<br>"; $b = '/this/is/a/test'; $b = ereg_replace("/[^/]*$", "", $b); print "$b<br>"; ?> Outputs: /usr/test /this/is/a -dan -- Dan Lowe <dan@tangledhelix.com> http://tangledhelix.com/ If it happens once, it's a bug. If it happens twice, it's a feature. If it happens more than twice, it's a design philosophy.

« previous php.general (#29776) next »