im using drupal,
I have a field, where users specify a price.
Ive printed the price field in my tpl.
<?php print $node->my_form['amt'] ?>
but the price comes out like 0.050, How do I get this to display £0.50?
See money_format() or see sprintf() or the printf variant:
<?php printf('£%01.2f', $node->my_form['amt']) ?>
Output: £0.05
Demo
See money_format().
you might want to check the details here http://www.drupalcommerce.org/faq/currency-format and make sure you have a currency formatter configured/chosen.
Depending also on how you're geting your prices, you might want to see this issue http://www.drupalcommerce.org/node/633 with the solution.
Related
I have a URL that contains a department name that will pull records from the database.
The URL looks like this: submissions.php?department=Settings,%20Security%20&%20Payments which is the equivalent of Settings, Security & Payments
My query needs to pull records from the table where the department is equal to Settings, Security & Payments.
How can convert that GET variable back to what I would expect it to be?
I tried html_entity_decode but it ignores the & and only gave me everything prior to that.
Whats the best way to do that?
Side note, if it was my data I would make it simple and pull it by ID but we dont have a table that has ID's for the departments.
Try urldecode()
You can see the manual here. http://uk3.php.net/urldecode
<?php
$string = "submissions.php?department=Settings,%20Security%20&%20Payments";
$decoded = urldecode($string);
echo "Original string: $string\n";
echo "Decoded string: $decoded\n";
?>
http://codepad.org/Bq1Gt30s
Use urldecode($your_URLstring)
I have following code which displays the price in Magento.
<?php echo $this->getPriceHtml($_product); ?>
I have to put this code inside echo instead and I can't get it to work.
I am trying
echo "$this->getPriceHtml ($_product)";
It just displays () on the page.
I tried other combinations and I can't come up with anything else.
What am I doing wrong?
Using single quotes will prevent $vars to be interpreted:
echo '$this->getPriceHtml ($_product)';
Or escape the $ sign:
echo "\$this->getPriceHtml (\$_product)";
http://php.net/manual/en/language.types.string.php
Or if by echo-ing you mean that you want to get something like
The price is 123.00
then do:
echo "The price is {$this->getPriceHtml($_product)}";
or even :
echo sprintf("The price is %s", $this->getPriceHtml($_product));
why not you are using this ?
$_product->getFinalPrice() or
if you want in formatted order then why you are not using this
number_format($pr->getPrice(), 2)
and if you want price with currency format then you can use this also
Mage::helper('core')->currency($pr->getPrice());
Hope it will help you.
:)
I am using a plugin that is generating my price value and pulling it from an array:
<?php echo __('Price: ', 'event_espresso'); ?></span> <?php echo
$org_options['currency_symbol'].$event->event_cost; ?>
I want to convert this generated value into my visitors own currency depending on the country their in with the plugin 'Worldcurrency'
However you have to input a value in the short code like so:
[worldcurrency curr="EUR" value="25"]
in united states will show:
(~30$ USD)
Now I know how to use a shortcode in a template php file but I don't know if its possible to insert my array value and currency symbol into this shortcode. Rather than using value="25" i need to use:
value="<?php echo $org_options['currency_symbol'].$event->event_cost; ?>"
Is this possible?
I'm not sure whether it's possible to use PHP code inline in a shortcode - and I suspect not, however an easy enough way to implement this would be to write a shortcode of your own that then called the other shortcode.
Your shortcode would generate the text you want (eg '[worldcurrency curr="EUR" value="25"]'), and call "do_shortcode($content)" which would then cause the other plugin to do the currency lookup for you.
You could put this in a plugin file and it would probably amount to less than 15 lines of code.
The other option is to modify the currency conversion plugin you are using to produce the output you want.
I have date in this format: 2010-01-11. I want to display JAN-11. How can i do this using php?
<?php echo date("M-y",strtotime("2010-01-11"));?>
Rudu's answer is correct, +1.
"M-y" would result to "Jan-11"
so if you need the output to be UPPERCASE, dont forget to use strtoupper().
<?php echo strtoupper(date("M-y",strtotime("2010-01-11")));?>
also bookmark this for later reference.
http://www.php.net/manual/en/function.date.php
Cheers
I have string like "Venditoris: Beware of Scams » Blog Archive » Trilegiant Complaints ..." in Database but when I try to display it ,It is not displaying.
So,I used html_entity_decode function but still it is not display.
I am Using cakePHP.below is my code to display that links.
echo $html->link(html_entity_decode(
$listing_end_arr[$i]['Listing']['listing_title'],ENT_QUOTES),
$listing_end_arr[$i]['Listing']['listing_url'],
array('target'=>'_blank', 'style'=>'color:'
. $colorArr[$listing_end_arr[$i]['Listing']['listing_sentiment']])) ;
Please Help me.
Check the CakePHP manual if you are using $html->link correctly. If so, var_dump the return value instead of echoing it. If it is empty, do
var_dump( $listing_end_arr[$i]['Listing'] );
to see what the Listing key contains. If the desired content is not in the dump, you know the error is elsewhere; probably in fetching the string from where it is stored.
Also, instead of using array[n][foo][bar][baz], consider assigning the subarray to a variable while looping over the array, e.g. $listing = array[n][foo][bar], so you can just do $listing[baz]. This will dramatically increase readability of your code.
inspect generated html first.. your code should echo a link, maybe it's just not visible (styling, color..).