HI everyone i’m trying to remove any character after the last occur of a / in a php variable making the result an other variable, i’m having trouble by deleting the content after the slash the only solution that came to my head is this
$result = substr($baseurl, 0, stripos($baseurl, "/") );
that obviously doesent work as it deletes after the first slash.
any help whould be really appreciated
@KarimCossutti – Have you tried rtrim? http://php.net/manual/en/function.rtrim.php
@KarimCossutti – I just found this on another site
string input = "http://www.somesite.com/somepage.aspx?whatever";
int index = input.LastIndexOf("/");
if (index > 0)
input = input.Substring(0, index); // or index + 1 to keep slash
Hi and thanks chris i tried to use the rtrim function but this is the result
$url = 'http://www.domain.ext/subf/page.html';
$result = rtrim($url, "/"); // Gives me the entire url
I want to point out that PHP is total voodoo to me i try to understand the best i can…
@KarimCossutti – are you just trying to get the directory?
would then become:
but it must work also with multiple sub folders
$string = '/tralala/bleh';
$plorp = substr(strrchr($string,'/'), 1);
$string = substr($string, 0, - strlen($plorp));
You can go 2 ways with this. Either use dirname() or use htaccess.
thanks Johan that worked
< ?php echo dirname("/page/test/test.php"); ?>
I’m worried that you are just copying and pasting solutions off the internet without fully understanding what they do. For example, why would they want a PHP_EOL on the end of this function?
You must be logged in to reply to this topic.