Re: I want to remove the last comma

From: Date: Wed, 13 Aug 2008 01:23:51 +0000
Subject: Re: I want to remove the last comma
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-45213@lists.php.net to get a copy of this message
On Wed, Aug 13, 2008 at 3:27 AM, A. Joseph <joefazee@gmail.com> wrote: > This the script > $dir = "images"; > $d = opendir($dir); > $out = " > var tinyMCEImageList = new Array(\n"; > while(false != ($entry = readdir($d))) { > if(preg_match("/(.jpg|.gif|.png)$/", $entry) != false) { > $out .= "['{$entry}', '{$dir}/{$entry}'],\n"; > } > > } > $out .= ");\n"; > > This the out put > > var tinyMCEImageList = new Array( > ['1_h_1.gif', 'images/1_h_1.gif'], > ['1_h_2.gif', 'images/1_h_2.gif'], > ['rss_2.jpg', 'images/rss_2.jpg'], > ['spacer.gif', 'images/spacer.gif'], # I want to remove this comma > ); > > if the last element (['spacer.gif', 'images/spacer.gif'],) contain comma, > javascript will return error, so i want to remove it. > try rtrim( $out, ', ' ). -- Regards, Wang Yi

« previous php.db (#45213) next »