ZEND currency symbol is displaying 1 - zend-framework

I'm using zend currency to display the currency based on locale. When I use the following code the symbol gets replaced by 1 instead of simply being removed:
$currency = new Zend_Currency($locale);
$currency->setFormat(array('symbol' => Zend_Currency::NO_SYMBOL));
What normally gets returned is this: € 2.500,01
but after the "setFormat" call I'm getting this: 1 2.500,01
I don't want the "1 " in there.
Any ideas on how to fix this?
Thanks.

Here's the ZF tutorial page for this. It looks like it will set a person in the right direction: zend currency tutorial page

You're setting the wrong option in setFormat. You need to set display to Zend_Currency::NO_SYMBOL. Like this:
$c = new Zend_Currency();
$c->setFormat(array('display' => Zend_Currency::NO_SYMBOL));
echo $c->toCurrency(2500.01);
Which outputs
2,500.01
The way you are currently doing it is literally setting the symbol to 1 because that's what the constant NO_SYMBOL evaluates to.

Related

Extract Two Value between special characters with Preg_Match

Hello I want to Extract the username and Password value with one preg_match_all
$url='http://xxxxxxxx.com:80/get.php?username=xxxxxx&password=xxxxxx&type=m3u_plus';
I get wiht this explode where i want but i know is more effect with preg_match_all can you show me how.?
$url_ext = parse_url($url);
$username=explode ("&",explode("=",$url_ext['query'])[1]);
$password=explode ("&",explode("=",$url_ext['query'])[2]);
I try with this code but not working
$lotes_fil='~https?://.\=(.+?)&~';
preg_match_all($lotes_fil,$url,$link_pre);
It is better to use parse_url and parse_str like explained here.
But, if you really want a regex, this does the job:
(?<=[?&])([^&=\r\n]+)=([^&=\r\n]+)
preg_match_all('/(?<=[?&])([^&=\r\n]+)=([^&=\r\n]+)/', $url, $matches);
The parameter name is in group 1, the value in group 2
Demo & explanation

How to change Php currency type to Dollar sign?

I am wondering why in my local, if I input value in Money type it will display
Php0.00 I want to display like $0.00
I tried to input value from Php0.00 to $0.00 but an error display.
maybe my setting it's default in Php, that's why I tried to changed it in setting but still does not work, any idea? thanks.
PHP also has money_format().
Here's an example:
echo money_format('$%i', 3.4); // echos '$3.40'
Check documentation for more...

How can I display count of imagefield images in views?

I want to display the number of images uploaded to an imagefield, in a views field or views tpl.php. How can I do this? My imagefield is called boatimages. I tried this but it comes out as 0, not the correct number: < ? php print count($fields->field_boatimages) ?>
Ack. I do not think count() works like that.
Why not just do this using Views? Take a look at Arguments > Settings and you'll see 'display record count' which seems like all you would need for this.
My suggestion is install the devel module and use the function dpm to print the variable if you wanna know the structure (print_r() may work too). If count isn't working it's because, you are probably using it with the wrong data.
OR, you could just query the database for the field. I'm gonna provide you instructions for drupal 7 but drupal 6 should be similar.
Check the table field_data_field_boatimages. See how there's a list of your images related with a single entity_id
Then execute this query
SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = ###
Where ### is the entity_id you want to know. You can get it by looking for arg(1) if arg(0) == node in your page.
Now you just have to use php power to print thar result
$query = SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = :eid
$result = db_query($query, array(':eid', $nid))->fetchField();
echo $result;
Drupal 6 would be very similar. Just a little difference in the table names and the query syntax. For example using db_result instead of fetchField()
Anyway good luck!

zfdatagrid date format

I am using ZF 1.11, PHP 5.3, Windows and the most recent version of zfdatagrid.
I use
$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));
to display an attribute "birthday" as dd-MM-yyyy. When I click on the Edit button (CRUD enabled), the value of this attribute is being displayed as 'yyyy-MM-dd'. When the user clicks the save button, he gets an error message (Please, enter date as dd-MM-yyyy).
How can I tell the $form to display the value as dd-MM-yyyy instead of yyyy-MM-dd?
looking at the docks I think your code maybe slighty incorrect:
$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));
Maybe:
$grid->updateColumn('birthday', array('format'=> 'date',array('date_format' => 'dd-MM-yyyy')));
looks like you had an extra array() at date.
reference:
Date ZFDatagrid will for a key in Zend_Registry with the name
Zend_Locale and use it. You can also pass as argument a instance of
Zend_Locale or an array with the following options
locale
date_format
type
$grid->updateColumn('field',array('format'=>'date'));
thanks, but that doesn't solve the problem. Actually, what I did now is to add an event listener for the crud.form_built event. The method called in this event simply creates a new Zend_Validate_Date object and assigns this validator to the corresponding zfdatagrid element.
This is a hack indeed, but it works. Actually, zfdatagrid doesn't really work with PostgreSQL and the manual is incorrent in many places.
!Warning maybe bad English!
for i.e. "localized" values in forms i do something like this..
after passing form to the grid $grid->setForm($myform);
but before the call of $grid->deploy();
i get the form element and set the value manually like the following
$Form=$grid->getForm(1);
$dateVal = $Form->getElement('birthday')->getValue();
if(Zend_Date::isDate($dateVal,'yyyy-MM-dd', 'en'))
$dateObject = new Zend_Date($dateVal);
$Form->getElement('birthday')
->setValue($dateObject->toString('dd.MM.yyyy'))
->setValidators(array(new Zend_Validate_Date('dd.MM.yyyy')))
;
then register a zfdatagrid event trigger "crud.before_update"
$grid->listenEvent('crud.before_update', array($this, '_updateCallback')
that calls a function from this controller _updateCallback() with something custom like this
public function _updateCallback(Bvb_Grid_Event $e)
{
$n = $e->getParam('newValues');
list($d,$m,$y) = explode('.', $n['birthday']);
$sqldate = $y.'-'.$m.'-'.$d;
$n['birthday'] = $sqldate;
$e->setParam('newValues', $n);
}
or just use Zend Date like before to refactor date to ensure that
the datevalue we want to save, is in a sql valid US date format..
hope this will help..
z.

How to deal with nameless forms on websites?

I would like to write a script that lets me use this website
http://proteinmodel.org/AS2TS/LGA/lga.html
(I need to use it a few hundred times, and I don't feel like doing that manually)
I have searched the internet for ways how this could be done using Perl, and I came across WWW::Mechanize, which seemed to be just what I was looking for. But now I have discovered that the form on that website which I want to use has no name - its declaration line simply reads
<FORM METHOD="POST" ACTION="./lga-form.cgi" ENCTYPE=multipart/form-data>
At first I tried simply not setting my WWW::Mechanize object's form_name property, which gave me this error message when I provided a value for the form's email address field:
Argument "my_email#address.com" isn't numeric in numeric gt (>) at /usr/share/perl5/WWW/Mechanize.pm line 1618.
I then tried setting form_name to '' and later ' ', but it was to no avail, I simply got this message:
There is no form named " " at ./automate_LGA.pl line 40
What way is there to deal with forms that have no names? It would be most helpful if someone on here could answer this question - even if the answer points away from using WWW::Mechanize, as I just want to get the job done, (more or less) no matter how.
Thanks a lot in advance!
An easy and more robust way is to use the $mech->form_with_fields() method from WWW::Mechanize to select the form you want based on the fields it contains.
Easier still, use the submit_form method with the with_fields option.
For instance, to locate a form which has fields named 'username' and 'password', complete them and submit the form, it's as easy as:
$mech->submit_form(
with_fields => { username => $username, password => $password }
);
Doing it this way has the advantage that if they shuffle their HTML around, changing the order of the forms in the HTML, or adding a new form before the one you're interested in, your code will continue to work.
I don't know about WWW::Mechanize, but its Python equivalent, mechanize, gives you an array of forms that you can iterate even if you don't know their names.
Example (taken from its homepage):
import mechanize
br = mechanize.Browser()
br.open("http://www.example.com/")
for form in br.forms():
print form
EDIT: searching in the docs of WWW::Mechanize I found the $mech->forms() method, that could be what you need. But since I don't know perl or WWW::Mechanize, I'll leave there my python answer.
Okay, I have found the answer. I can address the nameless form by its number (there's just one form on the webpage, so I guessed it would be number 1, and it worked). Here's part of my code:
my $lga = WWW::Mechanize->new();
my $address = 'my_email#address.com';
my $options = '-3 -o0 -d:4.0';
my $pdb_2 = "${pdb_id}_1 ${pdb_id}_2";
$lga->get('http://proteinmodel.org/AS2TS/LGA/lga.html');
$lga->success or die "LGA GET fail\n";
$lga->form_number(1);
$lga->field('Address', $address);
$lga->field('Options', $options);
$lga->field('PDB_2', $pdb_2);
$lga->submit();
$lga->success or die "LGA POST fail\n";