0
<?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?

vishu
  • 41
  • 4
  • Does your output (CLI or web browser) handle backspace as a display character? – Mark Baker Jun 22 '13 at 14:10
  • It works on the console (if there was a space after the BS), but not in webpages. – mario Jun 22 '13 at 14:10
  • It's not "working" because backspace has no special meaning when interpreted as text -- either plain or inside HTML. – Jon Jun 22 '13 at 14:10
  • 1
    Refer to this similar question: http://stackoverflow.com/questions/1440011/php-backspace-character-during-output-possible – ManuelH Jun 22 '13 at 14:11
  • I am not getting you @Mark Baker – vishu Jun 22 '13 at 14:17
  • you need to remove the last char from your string `substr($str, 0, strlen($str) - 1)` i hope that function names are right – DevZer0 Jun 22 '13 at 14:20
  • @vishu HTML or Windows CLI doesn't recognise a displayed x08 character as a backspace... in the CLI, it simply moves the cursor back one character. Try `echo "hello\x08" . "boy";` – Mark Baker Jun 22 '13 at 14:27

1 Answers1

1

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,",");}
Panama Jack
  • 24,158
  • 10
  • 63
  • 95