Php Flow » Php

How to remove one character from end of string

Now I had faced one problem to concatenate a string,Whenever I was got result string, an extra comma has been added end of result string.
Now below is code for remove the one extra character from string in php. Now I am using substr function to remove extra character.

Php Code for Remove Extra chracter from String
  1. $res=mysql_query($sqlArtist);  
  2.             while($row=mysql_fetch_row($res))  
  3.            {  
  4.             $stIds.=“‘”.$row[2].“‘,”;  
  5.            }  
  6.            $checkChr=substr(trim($stIds),-1);  
  7.            if($checkChr == ‘,’)  
  8.            {  
  9.             //delete , if it’s last character  
  10.             $stIds=substr(trim($stIds),0,-1);  
  11.            }  

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook. parvez1487(at)gmail(dot)com

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>