Avatar ·

How to get the last 7 characters of a string in PHP?

Hello everyone! I'm new to PHP and encountered a task: I need to extract the last 7 characters from a string. For example, I have a string with a date in the format "2023-10-15_12-30-45", and I need to get only the time part — the last 8 characters (actually 8, but in the task it's 7). I tried using substr() with a negative value, but for some reason it doesn't work. Here's my code: ```php $string = "Привет, мир! Это тестовая строка"; $last7 = substr($string, -7); echo $last7; // Outputs " строка" — this is 7 characters with a space, but I expected "строка" without the space? ``` Actually, I want to understand how to correctly use negative values in substr() and how to handle strings with Cyrillic characters? In my example the string is in Russian, and I noticed that substr() sometimes gives strange results.