I have made a system with browsing files; Now I have a problem:
My path string like this: A/Abba/2004/
I want to remove the text between the last 2 slashes (which is 2004 in this case).
So the output should look like A/Abba/
Can anyone help me as how to archive this in php?
Thanks.
If you try to remove last part of string you can do this this way:
$input = 'A/Abba/2014/';
$array = array_filter(explode('/', $input));
array_pop($array);
$correct = implode('/', $array);
array_filter removes empty strings from array
explode converts string to array by given delimiter
array_pop remove last item from given array
implode converts array to string using given 'glue'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With