Re: I want to remove the last comma

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What I would do is change
var tinyMCEImageList = new Array(\n";
to have a space and then the newline character at the end like so
var tinyMCEImageList = new Array( \n";

then change your last $out line
$out .= ");\n";
to strip the last 2 characters (which always gets called) and closes
the Array opening parenthesis.
$out = substr($out, 0, -2) . ");\n";

And your Javascript will always be able to be parsed even if there are
no elements in the array.

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

BTW, this is more of a general list question though, not a php-db question.

On Tue, Aug 12, 2008 at 2:27 PM, A. Joseph <joefazee@xxxxxxxxx> 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.
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux