Welcome Guest, Not a member yet? Register   Sign In
obtain all the characters before last forward slash of url?
#1

[eluser]Xeroxeen[/eluser]
Hi i want to get all the characters before last forward slash of a url.

Example -

"/public/images/userid/image.png" from this i want to get,

/public/images/userid/ only.So when i'm searching i got this.But it's not working.

Code:
$dir=substr( $imagepath, 0, strrpos( $imagepath, '/' ) );

plz help to solve this....
#2

[eluser]InsiteFX[/eluser]
Code:
public function reverse_strrchr($haystack, $needle)
{
     $pos = strrpos($haystack, $needle);

     if ($pos === FALSE)
     {
         return $haystack;
     }

     return substr($haystack, 0, $pos + 1);
}

$string = "/path/to/the/file/filename.php";

echo reverse_strrchr($string, '/');    // will echo "/path/to/the/file/"
#3

[eluser]Xeroxeen[/eluser]
[quote author="InsiteFX" date="1377379150"]
Code:
public function reverse_strrchr($haystack, $needle)
{
     $pos = strrpos($haystack, $needle);

     if ($pos === FALSE)
     {
         return $haystack;
     }

     return substr($haystack, 0, $pos + 1);
}

$string = "/path/to/the/file/filename.php";

echo reverse_strrchr($string, '/');    // will echo "/path/to/the/file/"
[/quote]

thanks.it's working properly




Theme © iAndrew 2016 - Forum software by © MyBB