Question

<?php
echo "hello\x08";
?>

the out put to this is coming as

hello

I am working on xampp as localhost

$reply='{';
        while($row=$this->conx->fetch_array($result)){
            $user=new user();
            $fullname=$user->get('fullname','id',$row['posted_by']);
            $now=getdat($row['posted_on']);
            $reply.='"count'.$count.'":{"id":'.$row['post_id'].',"user":"'.$fullname['fullname'].'","msg":"'.$row['msg'].'","at":"'.$now.'"},';
        }
        $reply.='}';
    return $reply;}

How can I remove the last ',' from reply?

Was it helpful?

Solution

Give this a try.

  $reply = rtrim($reply,",");

Using your example

$reply='{';
        while($row=$this->conx->fetch_array($result)){
            $user=new user();
            $fullname=$user->get('fullname','id',$row['posted_by']);
            $now=getdat($row['posted_on']);
            $reply.='"count'.$count.'":{"id":'.$row['post_id'].',"user":"'.$fullname['fullname'].'","msg":"'.$row['msg'].'","at":"'.$now.'"},';
        }
        $reply.='}';
    return rtrim($reply,",");}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top