how to remove last char from string

前端 未结 9 1122
天涯浪人
天涯浪人 2021-01-19 09:09

It might be a simple task. But I am new to PHP.

I am creating a string of values getting from database for a specific purpose.

How to remove last char from s

相关标签:
9条回答
  • 2021-01-19 10:01

    You might be better of just to use implode instead of this loop?

    implode ( "##" , $dataarray  );
    
    0 讨论(0)
  • 2021-01-19 10:03
    <?php
    $str = "1,2,3,4,5,";
    echo chop($str,",");
    ?>
    

    It will remove last comma (,) from the string $str

    0 讨论(0)
  • 2021-01-19 10:04

    Use substr:

    $str = substr($str,0, -2);
    

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

    0 讨论(0)
提交回复
热议问题