There is:
$string = "test.txt"; $pos = strrpos($string, '.'); echo substr($string, 0, $pos); I want to get txt and get test How to cut the string from the end to the point, I want to get the extension.
There is:
$string = "test.txt"; $pos = strrpos($string, '.'); echo substr($string, 0, $pos); I want to get txt and get test How to cut the string from the end to the point, I want to get the extension.
You can use pathinfo , which returns information about the path to the file.
Example:
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php'); echo $path_parts['dirname'], "\n"; echo $path_parts['basename'], "\n"; echo $path_parts['extension'], "\n"; // расширение файла echo $path_parts['filename'], "\n"; Accordingly, you can write like this:
$path = 'text.txt'; echo pathinfo($path)['extension']; Using substr (Returns a substring) and strrpos (Returns the position of the last occurrence of a substring in a string):
$path = 'text.txt'; echo substr($path, strrpos($path, '.') + 1); Source: https://ru.stackoverflow.com/questions/751741/
All Articles