Jump to content

PHP loop removing last comma


werushka

Recommended Posts

Hi, 

 

I have been trying to solve it but no luck, I have the following code 

 

<?php 
   foreach ($tickers as $i => $ticker) {
        
        {
            echo '{
                    "description": "",
                    "proName": "BITTREX:'. $ticker .'"
                     },';
        }
        }
 ?>

it gives me output like below

{ "description": "", "proName": "BITTREX:PTCBTC" },{ "description": "", "proName": "BITTREX:NEOSBTC" },

but I need to remove the last comma that is generated.

 

I would appreciate some feedback.

 

Thanks

Link to comment
Share on other sites

Guys. I understand that PHP people love to turn simple problems into fugly hacks with lots of bugs, but let's not be ridiculous. This is JSON. PHP knows JSON. Turning an array into a JSON document takes one function call. One. No loops, no string fumbling, no comma gymnastics. One function call. Writing this down is a matter of, say, 30 seconds including a quick check of the manual. Instead, you've already spent an hour banging your head against the wall. Even as a non-programmer, you should be able to see that this is not very smart.

Link to comment
Share on other sites

is this json???
 
 
<!-- TradingView Widget BEGIN -->
<span id="tradingview-copyright"><a ref="nofollow noopener" target="_blank" href="http://www.tradingview.com" style="color: rgb(173, 174, 176); font-family: "Trebuchet MS", Tahoma, Arial, sans-serif; font-size: 13px;">Quotes by <span style="color: #3BB3E4">TradingView</span></a></span>
<script src="https://s3.tradingvi...t-tickers.js">{
  "symbols": [
    {
      "description": "",
      "proName": "BITTREX:ARKBTC"
    },
    {
      "description": "",
      "proName": "BITTREX:OMGBTC"
    }
  ],
  "locale": "en"
}</script>
<!-- TradingView Widget END -->
 
 
What I am trying to do is get the tickers from cvs file so I don't waste space on the php file. Typing it manually for each ticker.
 
{
      "description": "",
      "proName": "BITTREX:OMGBTC"
 }
 
I am trying to change "BITTREX:OMGBTC" with the data pulled from cvs file for each line 
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.