Usuń ostatni znak z łańcucha [duplikat]
Możliwy duplikat:
PHP-Usuń ostatni znak, jeśli jest kropką?
Jaki jest najszybszy sposób na usunięcie ostatniego znaku z łańcucha?
Mam ciąg jak
a,b,c,d,e,
Chciałbym usunąć last', ' i odzyskać pozostały ciąg
OUTPUT: a,b,c,d,e
Jak najszybciej to zrobić? 612
4 answers
Najpierw próbuję bez spacji rtrim($arraynama,",");
i otrzymuję wynik błędu.
Następnie dodaję spację i uzyskuję dobry wynik: $newarraynama=rtrim($arraynama,", ");
1119
Author: markwalker_,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-09 09:00:29
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-09 09:00:29
Możesz użyć substr
echo substr('a,b,c,d,e,', 0, -1);
# => 'a,b,c,d,e'
754
Author: Nicola Peluchetti,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-09 08:25:59
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-09 08:25:59
Alternatywą dla substr
jest funkcja:
substr_replace($string, "", -1)
Czy to na czczo? Nie wiem, ale założę się, że te alternatywy są tak szybkie, że to po prostu nie ma znaczenia. 94
Author: bart,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-04-08 11:49:52
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-04-08 11:49:52
Możesz użyć
substr(string $string, int $start, int[optional] $length=null);
Zobaczsubstr W PHP docs. Zwraca część łańcucha.
11
Author: Peter Versnee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-16 13:10:33
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-16 13:10:33