Hi,
I have a string that is generated through a while loop. The result is like this..
aaa - bbb - ccc - ddd - eee - fff -
obviously, aaa, bbb,etc, are just placeholders, but my question is , how can I remove the last " - " but leave the ones inside?
Thanks,
Josh
Remove 3 chars from the end of a string
Moderator: General Moderators
Code: Select all
<?php
$string = "aaa - bbb - ccc - ddd - eee - fff - ";
echo substr($string, 0, -3);
?>[php_man]rtrim[/php_man]() works too:
Code: Select all
$trimmed = rtrim($string,' - ');Real programmers don't comment their code. If it was hard to write, it should be hard to understand.