Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 PHP 中创建逗号分隔列表,但是我无法弄清楚如何从字符串中删除尾随逗号 - 例如,我可能会生成一个看起来像这样的列表,
RefundApplicationForm_(1)7.pdf,Mackintosh_- Shaker -_Suite_1514.pdf,,,,
我试过了,
str_replace($list, ",", "");
但这会删除所有逗号我只想删除最后一个逗号和它们之间没有任何价值的任何逗号。
我通过执行以下操作来列出清单,
$list .= $value.",";
用这个
$list = rtrim($list, ',');
$list = substr($str, 0, -1); 我个人更喜欢相反的方式:以逗号开头,然后将其删除 $list = substr($str, 1);
$list = substr($str, 0, -1);
$list = substr($str, 1);