简体   繁体   English

如何从字符串末尾删除字符

[英]How to remove a character from the end of a string

我有以下字符串: $string = "username, email, status, password,"编辑:如何删除的最后一次出现,字符从字符串?

$string = trim($string,",");

That would work. 那行得通。 trim() on php.net 在php.net上trim()

如果要从$string删除最后一个字符,可以使用以下命令:

$string = substr($string, 0, -1);
$rest = substr("abcdef", 0, -1);  // returns "abcde"

来自http://php.net/manual/en/function.substr.php

$string = substr($string, 0, -1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从字符串末尾删除退格字符? - How to remove backspace character from the end of the string? 如何从字符串末尾删除ETX字符? (正则表达式或PHP) - How to remove ETX character from the end of a string? (Regex or PHP) 如何从php或regex中的字符串末尾删除特定字符 - How to Remove a specific character from the end of the string in php or regex 如何从PHP字符串的末尾删除特定字符 - How to Remove a specific character from the end of the string in php 从字符串末尾删除特定字符之后的字符串部分 - Remove portion of a string after a particular character from the end of the string 在 PHP 中删除从字符第一次出现到字符串末尾的所有内容 - Remove everything from the first occurrence of a character to the end of a string in PHP 删除特殊字符“ | ” 从字符串中忽略,如果它在开始 |“ End ”| 之间包含“,” - Remove special character “ | ” from a string ignore if it contains “,” between starts |“ End ”| 从字符串的开头或结尾删除非标准字符 - Remove Non Standard character from begining or end of string 如何使用preg_replace从某个字符中移除任何内容直到字符串结尾? - How to use preg_replace to remove anything from a certain character on until the end of a string? 如何从foreach循环的末尾删除字符串 - how to remove string from the end of foreach loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM