Running PHP 5.3 Can someone please tell me how to fix this piece of code that works in PHP 5.2 but not in PHP 5.3? $ConvertedCurrentPrice = number_format($ConvertedCurrentPrice, 2, '.' ,''); Thanks!
That line of code should work on all PHP versions >= 4. The only change to that function was in PHP 5.4:
Example: Price: $ (Blank - doesn't show a price) Should Be: Price: $100.00 (with the dollar amount and decimal point.
Can you please provide the actual code? Snippets, lines etc. and random result examples won't really be much help narrowing down the errors. Provide at least some (or all) of the content of $ConvertedCurrentPrice before the number_format, the surrounding presentational code etc.
if ($resp) { $results = ''; foreach($resp->ItemArray->Item as $item) { $link = $item->ViewItemURLForNaturalSearch; $title = $item->Title; $GalleryURL = $item->GalleryURL; $BidCount = $item->BidCount; $WatchCount = $item->WatchCount; $ItemID = $item->ItemID; $ConvertedCurrentPrice = $item->ConvertedCurrentPrice; $ConvertedCurrentPrice = number_format($ConvertedCurrentPrice, 2, '.' ,''); $PrimaryCategoryName = $item->PrimaryCategoryName; $TimeLeft = getPrettyTimeFromEbayTime($item->TimeLeft); $ViewItemURLForNaturalSearch = $item->ViewItemURLForNaturalSearch; $PrimaryCategoryID = $item->PrimaryCategoryID; $results .= "<div id='eb_item'> <div class='item_title'>" . $item->Title . " </div>"; $results .= "<div class='item_image'><img src=\"$item->GalleryURL\" alt=\"$item->Title \" width=90 height=85></div> \n"; $results .= "<div class='currprice'>"; $results .= "<span id='wbar'>Price:</span> <span id='pricebar'> $" . $ConvertedCurrentPrice . "</span></div>\n"; $results .= "<div class='ends'></div><br><div>
It was a really long dump, but here is the a piece of it. ["ConvertedCurrentPrice"]=> string(5) "20.89" ["ListingStatus"]=> string(6) "Active" ["TimeLeft"]=> string(13)
Then my suggestion is that something else is wrong - I'm thinking you're looking at the wrong line of code - although, if ConvertedCurrentPrice is an array to start with, you'll need too explicitly provide the correct array-key - like this $convertedcurrentprice = number_format($convertedcurrentprice[key]) (0,1,2 etc.) I tried a very convoluted experiment on my own server, and it runs just fine, and outputs the price, albeit that's on a 5.4.3 server - I highly doubt they fucked it up on 5.3
If your data is not sensitive/confidential, Before: foreach($resp->ItemArray->Item as $item) { Add file_put_contents('results.txt', seralize($resp)); And post the file here or PM it to me and I'll test it out for you and see where its going wrong.
This is the results page code that may be the problem. $results .= "<span id='wbar'>Price:</span> <span id='pricebar'> $" . $ConvertedCurrentPrice . "</span></div>\n";
There is no problem in that line of code. It's a simple string-assignment to an existing variable - and it's escaped properly, and using the correct quotes. Ergo, not the problem (at least not in that line).
Perhaps you could try commenting out a few lines of code such as $ConvertedCurrentPrice = $item->ConvertedCurrentPrice; // $ConvertedCurrentPrice = number_format($ConvertedCurrentPrice, 2, '.' ,''); or physically set the price $ConvertedCurrentPrice = 20.89; $ConvertedCurrentPrice = number_format($ConvertedCurrentPrice, 2, '.' ,''); To see what that outputs, I've test what you have above in various versions from 4.4 to 5.4 and none have a problem.