i have magento store need remove whitespace number can use later on dividing price , stuff.
the code simple this:
<script> var newprice = <?php echo $newprice;?> document.write(newprice); </script>
if price less 1000 (three numbers), outputs correctly. if price 4 numbers, wont output @ all. though can see source code variable stored correctly, example:
var newprice = 1 089
what need remove whitespace, doesnt seem easy. have tried:
var newprice = "<?php echo $newprice;?>" // quotes document.write(parseint(newprice));
this outputs "1". have tried following code, outputs 1 089 (with whitespace):
document.write(newprice.replace(" ", ""));
any ideas?
this odd. smell rat. think 'space' see may not space (ascii character code 32) other character maybe isn't in character set. in site set utf-8?
normally expect see comma or period here: "1,089"
or "1.089"
. thousands separator set in php locale. see output of localeconv()
i recommend study $newprice
set within magento code. think string. string displaying price in way makes sense humans.
for little computer needs number instead of string might better $_product->getfinalprice();
returns float or such function gets price number instead of human readable string.
failing that, based on suspicion 'space' not char(32), brute force preg_replace(anything isn't digit, period or comma)
may more effective string replacements (notwithstanding multi-byte character codes):
var newprice = <?php echo(preg_replace("#[^0-9\.\,].#","",(string)$newprice).";"); ?>
Comments
Post a Comment