Wednesday, October 26, 2011

Currency database - csv with currency symbol html codes

I couldnt find a currencies data file anywhere to import into a database. I wanted the currency name, abbreviation and the html code for the currency symbol, to use in select menus and such.

So I made a csv using the data from XE.com. That took a little time using regex to find and replace the table data and as it took a little time I thought I would share the file here for anyone else who may need currency data with html symbols for website use.

This is the csv data that can be copied and pasted into a file to import into a database table..

Albania Lek--ALL--Lek | Afghanistan Afghani--AFN--؋ | Argentina Peso--ARS--$ | Aruba Guilder--AWG--ƒ | Australia Dollar--AUD--$ | Azerbaijan New Manat--AZN--ман | Bahamas Dollar--BSD--$ | Barbados Dollar--BBD--$ | Belarus Ruble--BYR--p. | Belize Dollar--BZD--BZ$ | Bermuda Dollar--BMD--$ | Bolivia Boliviano--BOB--$b | Bosnia and Herzegovina Convertible Marka--BAM--KM | Botswana Pula--BWP--P | Bulgaria Lev--BGN--лв | Brazil Real--BRL--R$ | Brunei Darussalam Dollar--BND--$ | Cambodia Riel--KHR--៛ | Canada Dollar--CAD--$ | Cayman Islands Dollar--KYD--$ | Chile Peso--CLP--$ | China Yuan Renminbi--CNY--¥ | Colombia Peso--COP--$ | Costa Rica Colon--CRC--₡ | Croatia Kuna--HRK--kn | Cuba Peso--CUP--₱ | Czech Republic Koruna--CZK--Kč | Denmark Krone--DKK--kr | Dominican Republic Peso--DOP--RD$ | East Caribbean Dollar--XCD--$ | Egypt Pound--EGP--£ | El Salvador Colon--SVC--$ | Estonia Kroon--EEK--kr | Euro Member Countries--EUR--€ | Falkland Islands (Malvinas) Pound--FKP--£ | Fiji Dollar--FJD--$ | Ghana Cedis--GHC--¢ | Gibraltar Pound--GIP--£ | Guatemala Quetzal--GTQ--Q | Guernsey Pound--GGP--£ | Guyana Dollar--GYD--$ | Honduras Lempira--HNL--L | Hong Kong Dollar--HKD--$ | Hungary Forint--HUF--Ft | Iceland Krona--ISK--kr | India Rupee--INR--₹ | Indonesia Rupiah--IDR--Rp | Iran Rial--IRR--﷼ | Isle of Man Pound--IMP--£ | Israel Shekel--ILS--₪ | Jamaica Dollar--JMD--J$ | Japan Yen--JPY--¥ | Jersey Pound--JEP--£ | Kazakhstan Tenge--KZT--лв | Korea (North) Won--KPW--₩ | Korea (South) Won--KRW--₩ | Kyrgyzstan Som--KGS--лв | Laos Kip--LAK--₭ | Latvia Lat--LVL--Ls | Lebanon Pound--LBP--£ | Liberia Dollar--LRD--$ | Lithuania Litas--LTL--Lt | Macedonia Denar--MKD--ден | Malaysia Ringgit--MYR--RM | Mauritius Rupee--MUR--₨ | Mexico Peso--MXN--$ | Mongolia Tughrik--MNT--₮ | Mozambique Metical--MZN--MT | Namibia Dollar--NAD--$ | Nepal Rupee--NPR--₨ | Netherlands Antilles Guilder--ANG--ƒ | New Zealand Dollar--NZD--$ | Nicaragua Cordoba--NIO--C$ | Nigeria Naira--NGN--₦ | Korea (North) Won--KPW--₩ | Norway Krone--NOK--kr | Oman Rial--OMR--﷼ | Pakistan Rupee--PKR--₨ | Panama Balboa--PAB--B/. | Paraguay Guarani--PYG--Gs | Peru Nuevo Sol--PEN--S/. | Philippines Peso--PHP--₱ | Poland Zloty--PLN--zł | Qatar Riyal--QAR--﷼ | Romania New Leu--RON--lei | Russia Ruble--RUB--руб | Saint Helena Pound--SHP--£ | Saudi Arabia Riyal--SAR--﷼ | Serbia Dinar--RSD--Дин. | Seychelles Rupee--SCR--₨ | Singapore Dollar--SGD--$ | Solomon Islands Dollar--SBD--$ | Somalia Shilling--SOS--S | South Africa Rand--ZAR--R | Korea (South) Won--KRW--₩ | Sri Lanka Rupee--LKR--₨ | Sweden Krona--SEK--kr | Switzerland Franc--CHF--CHF | Suriname Dollar--SRD--$ | Syria Pound--SYP--£ | Taiwan New Dollar--TWD--NT$ | Thailand Baht--THB--฿ | Trinidad and Tobago Dollar--TTD--TT$ | Turkey Lira--TRY--TL | Turkey Lira--TRL--₤ | Tuvalu Dollar--TVD--$ | Ukraine Hryvna--UAH--₴ | United Kingdom Pound--GBP--£ | United States Dollar--USD--$ | Uruguay Peso--UYU--$U | Uzbekistan Som--UZS--лв | Venezuela Bolivar Fuerte--VEF--Bs | Viet Nam Dong--VND--₫ | Yemen Rial--YER--﷼ | Zimbabwe Dollar--ZWD--Z$




I created a mysql table with 4 columns, id,name,abb,html and then loaded the above data in phpmyadmin using the following mysql

LOAD DATA LOCAL INFILE '/path/to/currencies/file.txt' INTO TABLE `currency` FIELDS TERMINATED BY '--' ESCAPED BY '\\' LINES TERMINATED BY ' | '(
`name` , `abb` , `html`
)






This is the currency data that is contained, and how the html codes display...


Albania Lek - ALL - Lek
Afghanistan Afghani - AFN - ؋
Argentina Peso - ARS - $
Aruba Guilder - AWG - ƒ
Australia Dollar - AUD - $
Azerbaijan New Manat - AZN - ман
Bahamas Dollar - BSD - $
Barbados Dollar - BBD - $
Belarus Ruble - BYR - p.
Belize Dollar - BZD - BZ$
Bermuda Dollar - BMD - $
Bolivia Boliviano - BOB - $b
Bosnia and Herzegovina Convertible Marka - BAM - KM
Botswana Pula - BWP - P
Bulgaria Lev - BGN - лв
Brazil Real - BRL - R$
Brunei Darussalam Dollar - BND - $
Cambodia Riel - KHR - ៛
Canada Dollar - CAD - $
Cayman Islands Dollar - KYD - $
Chile Peso - CLP - $
China Yuan Renminbi - CNY - ¥
Colombia Peso - COP - $
Costa Rica Colon - CRC - ₡
Croatia Kuna - HRK - kn
Cuba Peso - CUP - ₱
Czech Republic Koruna - CZK - Kč
Denmark Krone - DKK - kr
Dominican Republic Peso - DOP - RD$
East Caribbean Dollar - XCD - $
Egypt Pound - EGP - £
El Salvador Colon - SVC - $
Estonia Kroon - EEK - kr
Euro Member Countries - EUR - €
Falkland Islands (Malvinas) Pound - FKP - £
Fiji Dollar - FJD - $
Ghana Cedis - GHC - ¢
Gibraltar Pound - GIP - £
Guatemala Quetzal - GTQ - Q
Guernsey Pound - GGP - £
Guyana Dollar - GYD - $
Honduras Lempira - HNL - L
Hong Kong Dollar - HKD - $
Hungary Forint - HUF - Ft
Iceland Krona - ISK - kr
India Rupee - INR - ₹
Indonesia Rupiah - IDR - Rp
Iran Rial - IRR - ﷼
Isle of Man Pound - IMP - £
Israel Shekel - ILS - ₪
Jamaica Dollar - JMD - J$
Japan Yen - JPY - ¥
Jersey Pound - JEP - £
Kazakhstan Tenge - KZT - лв
Korea (North) Won - KPW - ₩
Korea (South) Won - KRW - ₩
Kyrgyzstan Som - KGS - лв
Laos Kip - LAK - ₭
Latvia Lat - LVL - Ls
Lebanon Pound - LBP - £
Liberia Dollar - LRD - $
Lithuania Litas - LTL - Lt
Macedonia Denar - MKD - ден
Malaysia Ringgit - MYR - RM
Mauritius Rupee - MUR - ₨
Mexico Peso - MXN - $
Mongolia Tughrik - MNT - ₮
Mozambique Metical - MZN - MT
Namibia Dollar - NAD - $
Nepal Rupee - NPR - ₨
Netherlands Antilles Guilder - ANG - ƒ
New Zealand Dollar - NZD - $
Nicaragua Cordoba - NIO - C$
Nigeria Naira - NGN - ₦
Korea (North) Won - KPW - ₩
Norway Krone - NOK - kr
Oman Rial - OMR - ﷼
Pakistan Rupee - PKR - ₨
Panama Balboa - PAB - B/.
Paraguay Guarani - PYG - Gs
Peru Nuevo Sol - PEN - S/.
Philippines Peso - PHP - ₱
Poland Zloty - PLN - zł
Qatar Riyal - QAR - ﷼
Romania New Leu - RON - lei
Russia Ruble - RUB - руб
Saint Helena Pound - SHP - £
Saudi Arabia Riyal - SAR - ﷼
Serbia Dinar - RSD - Дин.
Seychelles Rupee - SCR - ₨
Singapore Dollar - SGD - $
Solomon Islands Dollar - SBD - $
Somalia Shilling - SOS - S
South Africa Rand - ZAR - R
Korea (South) Won - KRW - ₩
Sri Lanka Rupee - LKR - ₨
Sweden Krona - SEK - kr
Switzerland Franc - CHF - CHF
Suriname Dollar - SRD - $
Syria Pound - SYP - £
Taiwan New Dollar - TWD - NT$
Thailand Baht - THB - ฿
Trinidad and Tobago Dollar - TTD - TT$
Turkey Lira - TRY - TL
Turkey Lira - TRL - ₤
Tuvalu Dollar - TVD - $
Ukraine Hryvna - UAH - ₴
United Kingdom Pound - GBP - £
United States Dollar - USD - $
Uruguay Peso - UYU - $U
Uzbekistan Som - UZS - лв
Venezuela Bolivar Fuerte - VEF - Bs
Viet Nam Dong - VND - ₫
Yemen Rial - YER - ﷼
Zimbabwe Dollar - ZWD - Z$

Monday, October 24, 2011

PHP - function to search an associative array

To find the value of part of an associative array such as the one below, the function below will search for a term within the key that is specified in the function...

$arr = "Array ( [0] => Array ( [id] => 1 [date] => 2011-10-18 [details] => Shopping ) [1] => Array ( [id] => 2 [date] => 2011-10-01 [details] => Tax ) [2] => Array ( [id] => 123 [date] => 2011-10-18 [details] => Petrol )";



function getKeys($arr,$search){
foreach($arr as $keys=>$values)
{
foreach ($values as $key => $value) {
if($key=="date" && $value==$search){//$key=="date" can be any key from the array
$getkeys.=$keys.",";
}
}
}
$len=strlen($getkeys)-1; //get the length of $getkeys
$getkeys=substr($getkeys,0,$len); //remove the last comma
$getkeys=$pieces = explode(",", $getkeys); //make an arrayof the keys
return $getkeys;
}//end function getKeys

$getkeys=getKeys($arr,"2011-10-18");//search term can be anything, here it is a date
print_r($getkeys);//print the array


This will return an array of the keys of the elements of the array in which the search term was found. In this case Array ( [0] => 0 [1] => 2 )

Monday, October 17, 2011

MySQL resultset as an associative array

To save time and resources, when a php application is going to require the same resultset often, the resultset can be saved in a session as an associative array. Then when required in the script the saved session data can be referenced instead of querying the database again.

To return a resultset as an array named $ac_arr requires the following mysql...

$result=mysql_query("SELECT name,startdate,enddate FROM accounts") or die(mysql_error());

while(($ac_arr[] = mysql_fetch_assoc($result)) || array_pop($ac_arr));

The array_pop() function simply removes the extra element that would otherwise be appended to the array.

This can then be stored in a session variable and later referenced without re-querying the database...


$_SESSION['ac_array']=$ac_arr;

To list the keys and values of elements in the array

<?php
$acs=$_SESSION['ac_array'];
foreach($acs as $keys=>$values)
{
foreach ($values as $key => $value) {
echo $keys." : ".$key.":".$value."<br />";
}
}
?>

The above will display a list like this
0 : name : AC1
0 : startdate : 2011-08-16
0 : enddate : 2011-12-16
1 : name : AC2
1 : startdate : 2014-07-25
1 : enddate : 2024-07-25
2 : name : AC3
2 : startdate : 2012-05-10
2 : enddate : 2022-05-10

so you can reference any element in the array by calling
$acs[0][name] (will return AC1)
$acs[2][startdate] (will return 2012-05-10)

Sunday, October 16, 2011

Amino Acids In protein - Complementary protein sources

When eating a vegetarian diet, it is important to get the protein right.

Usually the protein content of various food is labelled in grams, but not all protein is equal. The combination of amino acids that make up the protein does matter.

For example, a person could get (for example) 10g protein from 100g wholewheat bread. However the human body would be unable to utilise all that protein, as wheat protein does not contain all the essential amino acids (the amino acids that the body has to be fed, as it can not make them itself). A food that contains all the essential amino acids is called a "complete protein". Vegetarian sources are dairy products, quinoa, soya. A food that contains protein but not all the essential amino acids is called an incomplete protein. An incomplete protein has some amino acids that limit it, these are called "limiting amino acids". In wheat (and most grain) protein for example, the limiting amino acid is lysine. As the body uses amino acids together to do stuff, in a ratio, it can therefor only process as much protein as the limiting amino acid allows.

So that is why it is necessary to complement vegetarian protein sources sometimes. For example mixing wheat or rice protein, with a legume protein (rice and dal, beans on toast, tortilla and refreid beans), results in all essential amino acids being present. As although wheat and rice lack lysine,it has plenty of methionine and tryptophan. Legumes are high in lysine, but low in methionine and tryptophan. Together they form a complementary protein.

I found a good utility online to check the amino acid profile of foods (from the USDA database)
Amino Acid Check

This can help to choose a variety of foods over a course of a day that will complement each other, so providing enough of all the essential amino acids.

I was surprised to see that most green vegetables, spinach, broccoli etc, in fact have excellent amino acid profiles, with all the essential amino acids contained. Obviously you would have to eat alot of greens to get the rda of protein, but I have read that our ancestors, in paleolithic times, might have eaten several carrier bag fulls of green leafy veg a day.

An interesting fact for weight watchers, is that 600g of broccoli, contains nearly 20g protein and under 150 calories. Weight watchers usually like to eat food that keeps them nice and full up without having too many cals. The equivalent calorie amount of rice, would be just around 35g, and would only provide about 3g protein. If hungry, I know which choice i would go for to keep me full for longer!

As a side note, recent reports state that eating broccoli along with something spicy such as mustard or horseradish, boosts it anto cancer properties. Vegetables have so many wonderful properties, that are only just being discovered.

I once used the USDA database to analyse my daily food intake and discovered that by eating 5 portions of fruit and veg a day, I was not achieveing the rda of all the nutrients. In fact to do so a person has to eat a really wide range of fruit and veg and in quite large quantities. Americas 7 a day advice is better, but still, it depends on what you choose. It is a complicated science really.

This post is about amino acids in protein though, it is a huge subject, but really important for vegetarians to get to grips with, as amino acids are the building blocks of life. Every part of the human bodily system requires amino acids to function and renew. From blood, skin and cartilage, to muscles and bones, hormones and enzymes. It is all very well taking a multi vitamin, but without amino acids, the vitamins and minerals will have nothing to act with.

Personally as a vegetarian for many years, I now have a couple of scoops of whey protein powder daily, to be certain that my body always has a good supply of these treasures. It also saves me having to think too much about combining other protein sources and I do like to keep my life simple!




Essential Amino Acids Important Functions In The Body:


Isoleucine (Ile) - for muscle production, maintenance and recovery after workout. Involved in hemoglobin formation, blood sugar levels, blood clot formation and energy.
Leucine (Leu) - growth hormone production, tissue production and repair, prevents muscle wasting, used in treating conditions such as Parkinson’s disease.
Lysine (Lys) - calcium absorption, bone development, nitrogen maintenance, tissue repair, hormone production, antibody production.
Methionine (Met) - fat emulsification, digestion, antioxidant (cancer prevention), arterial plaque prevention (heart health), and heavy metal removal.
Phenylalanine (Phe) - tyrosine synthesis and the neurochemicals dopamine and norepinephrine. Supports learning and memory, brain processes and mood elevation.
Threonine (Thr) monitors bodily proteins for maintaining or recycling processes.
Tryptophan (Trp) - niacin production, serotonin production, pain management, sleep and mood regulation.
Valine (Val) helps muscle production, recovery, energy, endurance; balances nitrogen levels; used in treatment of alcohol related brain damage.
Histidine (His) - the 'growth amino' essential for young children. Lack of histidine is associated with impaired speech and growth. Abundant in spirulina, seaweed, sesame, soy, rice and legumes.

cite

Wednesday, October 12, 2011

PHP - Get the last day of a month


<?php
function GetLastDayofMonth($year, $month) {
for ($day=31; $day>=28; $day--) {
if (checkdate($month, $day, $year)) {
return $day;
}
}
}
?>


Then to call the last day of the month

$lastdayofmonth = GetLastDayofMonth(2011, 02);
echo $lastdayofmonth;


This would print the last day of the month of February 2011

The function is in the notes for the checkdate php function at
http://php.net/manual/en/function.checkdate.php