I have a string.

$Order="order1,order2,order3,";

If you noticed, there is a , at the back of order 3. I would like to know how to remove that. Can anyone help pls???

Thank you.
Rdgs.

    $Order = "order1,order2,order3,";
    $Order = substr(0,strlen($Order)-1,$Order);

      Just a note... you have the arguments in the wrong order:

      $order = "order1,order2,order3,";
      $order = substr($order, 0, -1);

      $order will now be: "order1,order2,order3"

      There is also a new feature in PHP4.0.7 for rtrim(), which makes it more like the chop() function in perl. If you do have that version, you can use:

      $order = "order1,order2,order3,";
      $order = rtrim($order, ",");

      This allows you to specify the actual characters you want to "chop off".

      http://www.php.net/manual/en/function.rtrim.php

      Regards

        Ah, indeed, I did. Thanks. And thanks for the rtrim() pointer -- indeed more elegant.

          Write a Reply...