I'm looking for some function that will delete everything after the last backslash (/), including the backslash.
In example;
before: /home/to/folder
after: /home/to
delete everything after last /
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
function delete_backslash($str){
$array = explode("/", $str);
$key = count($array) - 1;
unset($arrayї$key]);
$str = implode("/", $array);
return $str;
}or simplyor if it might be that there is no / in the string
Code: Select all
<?php
$before = '/home/to/folder';
$after = substr($before, $after, strrpos($before, '/'));
echo $after;
?>Code: Select all
<?php
$before = 'hometofolder';
if($pos=strrpos($before, '/'))
$after = substr($before, $after, pos);
echo $after;
?>-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
A much simpler method is:
Code: Select all
$after = dirname($before);