Search code examples
phptrim

Why rtrim remove trailing zeros?


I to want trim (+06) from 12:00 (+06). So, I have used rtrim. I expect it returns me 12:00 but it actually returns 12:

<?php
  $str = "12:00 (+06)";
  echo rtrim($str," (+06)");
?>

Can anyone help me out.


Solution

  • Just do (without leading space before the left parenthesis). Rtrim strips ordinary spaces without defining it which seems to be the issue here. To be honest: I don't know why the rest is 12 and not 12:00 but without the space it works:

    echo rtrim($str,"(+06)");
    

    Are you only looking for the left part of the string and it's always the same number of characters, you could do this:

    $str = substr($str,0,5);`