Euro foreign exchange reference rates in xml format

http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev

14/01/2015

Magic Constants

Name Description
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
__DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)
__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__CLASS__ The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.
__TRAIT__ The trait name. (Added in PHP 5.4.0) As of PHP 5.4 this constant returns the trait as it was declared (case-sensitive). The trait name includes the namespace it was declared in (e.g. Foo\Bar).
__METHOD__ The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).
__NAMESPACE__ The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0).
http://php.net/manual/en/language.constants.predefined.php

14/01/2015

php class list

get_class — Returns the name of the class of an object get_parent_class — Retrieves the parent class name for object or class is_subclass_of — Checks if the object has this class as one of its parents
get_class_vars — Get the default properties of the class get_object_vars — Gets the properties of the given object property_exists — Checks if the object or class has a property

14/01/2015

xml Entity escaping code

Entity escaping Your Sitemap file must be UTF-8 encoded (you can generally do this when you save the file). As with all XML files, any data values (including URLs) must use entity escape codes for the characters listed in the table below. Character Escape Code Ampersand      :     &       &amp; Single Quote    :     '         &apos; Double Quote  :     "         &quot; Greater Than   :     >        &gt; Less Than        :     <        &lt; In addition, all URLs (including the URL of your Sitemap) must be URL-escaped and encoded for readability by the web server on which they are located. However, if you are using any sort of script, tool, or log file to generate your URLs (anything except typing them in by hand), this is usually already done for you. Please check to make sure that your URLs follow the RFC-3986 standard for URIs, the RFC-3987 standard for IRIs, and the XML standard. Below is an example of a URL that uses a non-ASCII character (ü), as well as a character that requires entity escaping (&): http://www.example.com/ümlat.php&q=name Below is that same URL, ISO-8859-1 encoded (for hosting on a server that uses that encoding) and URL escaped: http://www.example.com/%FCmlat.php&q=name Below is that same URL, UTF-8 encoded (for hosting on a server that uses that encoding) and URL escaped: http://www.example.com/%C3%BCmlat.php&q=name Below is that same URL, but also entity escaped: http://www.example.com/%C3%BCmlat.php&amp;q=name   [php] <pre><code>function xml_entities($string) { return strtr( $string, array( "<" => "&lt;", ">" => "&gt;", '"' => "&quot;", "'" => "&apos;", "&" => "&amp;", ) ); } [/php]

14/01/2015

Php in_array_r function - check if an array exist in 2 dimentional array

in_array_r $needle, $2darray, 2 dimentional array  to be searched $uniqueKey   -----> $needle['ID'] [php] function in_array_r($needle, $2darray,$uniqueKey) { $found = false; foreach ($2darray as $item) { if ($item[$uniqueKey] == $needle[$uniqueKey]) { $found = true; break; } elseif (is_array($item)) { $found = in_array_r($needle, $item); if($found) { break; } } } return $found; } &nbsp; [/php]

14/01/2015

array sorting algoritm

[php] <?php function arrayUnique($array, $preserveKeys = false) { // Unique Array for return $arrayRewrite = array(); // Array with the md5 hashes $arrayHashes = array(); foreach($array as $key => $item) { // Serialize the current element and create a md5 hash $hash = md5(serialize($item)); // If the md5 didn't come up yet, add the element to // to arrayRewrite, otherwise drop it if (!isset($arrayHashes[$hash])) { // Save the current element hash $arrayHashes[$hash] = $hash; // Add element to the unique Array if ($preserveKeys) { $arrayRewrite[$key] = $item; } else { $arrayRewrite[] = $item; } } } return $arrayRewrite; } $input = array( array( 'id' => 123, 'ean' => '1234567890123' ), array( 'id' => 123, 'ean' => '4852950174938' ), array( 'id' => 123, 'ean' => '1234567890123' ), ); $input = arrayUnique($input); print_r($input); ?> [/php] 2 dimentional array sorting by key [php]</pre> function sortMultiArrayByKey($argArray, $argKey, $argOrder=SORT_ASC){ foreach ($argArray as $key => $row){ $key_arr[$key] = $row[$argKey]; } array_multisort($key_arr, $argOrder, $argArray); return $argArray; } <pre> output: <strong></strong> Array ( [0] => Array ( [id] => 123 [ean] => 1234567890123 ) [1] => Array ( [id] => 123 [ean] => 4852950174938 ) ) <strong></strong> [/php]

14/01/2015

PHP Directory Functions

  scandir — List files and directories inside the specified path ref : http://www.php.net/manual/en/function.scandir.php

14/01/2015

Php money_format — Formats a number as a currency string

money_format — Formats a number as a currency string

[php]<?php

$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56
[/php]



[php]
// Italian national format with 2 decimals`
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
// Eu 1.234,56

// Using a negative number
$number = -1234.5672;

// US national format, using () for negative numbers
// and 10 digits for left precision
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($        1,234.57)

// Similar format as above, adding the use of 2 digits of right
// precision and '*' as a fill character
echo money_format('%=*(#10.2n', $number) . "\n";
// ($********1,234.57)

// Let's justify to the left, with 14 positions of width, 8 digits of
// left precision, 2 of right precision, withouth grouping character
// and using the international format for the de_DE locale.
setlocale(LC_MONETARY, 'de_DE');
echo money_format('%=*^-14#8.2i', 1234.56) . "\n";
// Eu 1234,56****

// Let's add some blurb before and after the conversion specification
setlocale(LC_MONETARY, 'en_GB');
$fmt = 'The final value is %i (after a 10%% discount)';
echo money_format($fmt, 1234.56) . "\n";
// The final value is  GBP 1,234.56 (after a 10% discount)

?>

[/php]

14/01/2015

Php Math Functions List

floor — Round fractions down [php]<?php echo floor(4.3);   // 4 echo floor(9.999); // 9 echo floor(-3.14); // -4 ?>[/php] [/php]
fmod — Returns the floating point remainder (modulo) of the division of the arguments
[php]<?php
$x = 5.7;
$y = 1.3;
$r = fmod($x, $y);
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7
?>

[/php]

ceil — Round fractions up

[php]<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
?>

[/php]

round — Rounds a float

[php]<?php
echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.6, 0);      // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);    // 5.05
echo round(5.055, 2);    // 5.06
?>[/php]

number_format — Format a number with grouped thousands

[php]<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

[/php]
										

14/01/2015

Some php Functions

realpath — Returns canonicalized absolute pathname __DIR__ [php] echo realpath(__FILE__); [/php] output: /home/develop1/public_html/ContactForm.php parse_str parse_url     [php] print(__FILE__); echo '<br>'; echo'PATHINFO_DIRNAME: '. pathinfo(__FILE__, PATHINFO_DIRNAME); echo '<br>'; echo'PATHINFO_BASENAME: '. pathinfo(__FILE__, PATHINFO_BASENAME); echo '<br>'; echo'PATHINFO_EXTENSION: '. pathinfo(__FILE__, PATHINFO_EXTENSION); echo '<br>'; &nbsp; Output: /home/develop1/public_html/folder/example.php PATHINFO_DIRNAME: /home/develop1/public_html/folder PATHINFO_BASENAME: example.php PATHINFO_EXTENSION: php [/php]

14/01/2015

Php - OOP - method_exists function

method_exists: Checks if the class method exists in the given object. [php]<?php $directory = new Directory('.'); var_dump(method_exists($directory,'read'));  // return   bool(true)  if function exist ?>[/php] func_num_args — Returns the number of arguments passed to the function [php] <?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; } foo(1, 2, 3); ?> [/php] Output: Number of arguments: 3

14/01/2015

Php Date

[php] &nbsp; echo  mktime;  //  prints now $1day=86400; $1month=86400*30; strtotime — Parse about any English textual datetime description into a Unix timestamp strtotime("06/11/2013 12:30"); // return 12321423423 [/php] Formating Date : [php] echo date("m/d/Y H:i",mktime()); [/php]

14/01/2015

Php - OOP- call_user_func

call_user_func — Call the callback given by the first parameter [php] <?php error_reporting(E_ALL); function increment(&$var) { $var++; } $a = 0; call_user_func('increment', $a); echo $a."\n"; call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3 echo $a."\n"; ?> [/php] call_user_func_array — Call a callback with an array of parameters [php] <?php function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2\n"; } class foo { function bar($arg, $arg2) { echo __METHOD__, " got $arg and $arg2\n"; } } // Call the foobar() function with 2 arguments call_user_func_array("foobar", array("one", "two")); // Call the $foo->bar() method with 2 arguments $foo = new foo; call_user_func_array(array($foo, "bar"), array("three", "four")); ?> [/php]

14/01/2015

Regex quick reference

[abc] A single character of: a, b or c
[^abc] Any single character except: a, b, or c
[a-z] Any single character in the range a-z
[a-zA-Z] Any single character in the range a-z or A-Z
^ Start of line
$ End of line
\A Start of string
\z End of string
. Any single character
\s Any whitespace character
\S Any non-whitespace character
\d Any digit
\D Any non-digit
\w Any word character (letter, number, underscore)
\W Any non-word character
\b Any word boundary
(...) Capture everything enclosed
(a|b) a or b
a? Zero or one of a
a* Zero or more of a
a+ One or more of a
a{3} Exactly 3 of a
a{3,} 3 or more of a
a{3,6} Between 3 and 6 of a

14/01/2015

jQuery clear form function

  [code lang="js"] $.fn.clearForm = function() { return this.each(function() { var type = this.type, tag = this.tagName.toLowerCase(); if (tag == 'form') return $(':input',this).clearForm(); if (type == 'text' || type == 'password' || tag == 'textarea') this.value = ''; else if (type == 'checkbox' || type == 'radio') this.checked = false; else if (tag == 'select') this.selectedIndex = -1; }); }; [/code] How to use: $("#formID").clearForm();

14/01/2015

php if like ? :

[php] if(x==y){ $z=0; }else{ $z=1; } [/php] example : [php] $z=(x=y ? 0 : 1 ); [/php]

14/01/2015

Php pathinfo() function

[php] <?php print(__FILE__); echo '<br>'; echo'PATHINFO_DIRNAME: '. pathinfo(__FILE__, PATHINFO_DIRNAME); echo '<br>'; echo'PATHINFO_BASENAME: '. pathinfo(__FILE__, PATHINFO_BASENAME); echo '<br>'; echo'PATHINFO_EXTENSION: '. pathinfo(__FILE__, PATHINFO_EXTENSION); echo '<br>'; ?> [/php] => visual is below /home/natural/public_html/dd/dd.php PATHINFO_DIRNAME: /home/natural/public_html/dd PATHINFO_BASENAME: dd.php PATHINFO_EXTENSION: php

14/01/2015

Php Regular Expressions

Regular ExpressionWill match...
fooThe string "foo"
^foo"foo" at the start of a string
foo$"foo" at the end of a string
^foo$"foo" when it is alone on a string
[abc]a, b, or c
[a-z]Any lowercase letter
[^A-Z]Any character that is not a uppercase letter
(gif|jpg)Matches either "gif" or "jpeg"
[a-z]+One or more lowercase letters
[0-9\.\-]?ny number, dot, or minus sign
^[a-zA-Z0-9_]{1,}$Any word of at least one letter, number or _
([wx])([yz])wy, wz, xy, or xz
[^A-Za-z0-9]Any symbol (not a number or a letter)
([A-Z]{3}|[0-9]{4})Matches three letters or four numbers



Regular Expressions Reference Sheet

CharacterDefinitionExample

^

The pattern has to appear at the beginning of a string.^cat matches any string that begins with cat

$

The pattern has to appear at the end of a string.cat$ matches any string that ends with cat

.

Matches any character.cat. matches catT and cat2 but notcatty

[]

Bracket expression. Matches one of any characters enclosed.gr[ae]y matches gray or grey

[^]

Negates a bracket expression. Matches one of any characters EXCEPT those enclosed.1[^02] matches 13 but not 10 or12

[-]

Range. Matches any characters within the range.[1-9] matches any single digit EXCEPT 0

?

Preceeding item must match one or zero times.colou?r matches color or colour but not colouur

+

Preceeding item must match one or more times.be+ matches be or bee but not b

*

Preceeding item must match zero or more times.be* matches b or be orbeeeeeeeeee

()

Parentheses. Creates a substring or item that metacharacters can be applied toa(bee)?t matches at or abeet but not abet

{n}

Bound. Specifies exact number of times for the preceeding item to match.[0-9]{3} matches any three digits

{n,}

Bound. Specifies minimum number of times for the preceeding item to match.[0-9]{3,} matches any three or more digits

{n,m}

Bound. Specifies minimum and maximum number of times for the preceeding item to match.[0-9]{3,5} matches any three, four, or five digits

|

Alternation. One of the alternatives has to match.July (first|1st|1) will match July 1stbut not July 2

POSIX Character Classes

CharacterDefinitionExample

[:alnum:]

alphanumeric character[[:alnum:]]{3} matches any three letters or numbers, like 7Ds

[:alpha:]

alphabetic character, any case[[:alpha:]]{5} matches five alphabetic characters, any case, like aBcDe

[:blank:]

space and tab[[:blank:]]{3,5} matches any three, four, or five spaces and tabs

[:digit:]

digits[[:digit:]]{3,5} matches any three, four, or five digits, like 3, 05, 489

[:lower:]

lowercase alphabetics[[:lower:]] matches a but not A

[:punct:]

punctuation characters[[:punct:]] matches ! or . or , but not a or 3

[:space:]

all whitespace characters, including newline and carriage return[[:space:]] matches any space, tab, newline, or carriage return

[:upper:]

uppercase alphabetics[[:upper:]] matches A but not a

Perl-Style Metacharacters

CharacterDefinitionExample

//

Default delimiters for pattern/colou?r/ matches color or colour

i

Append to pattern to specify a case insensitive match/colou?r/i matches COLOR orColour

\b

A word boundary, the spot between word (\w)and non-word (\W) characters/\bfred\b/i matches Fred but notAlfred or Frederick

\B

A non-word boundary/fred\B/i matches Frederick but notFred

\d

A single digit character/a\db/i matches a2b but not acb

\D

A single non-digit character/a\Db/i matches aCb but not a2b

\n

The newline character. (ASCII 10)/\n/ matches a newline

\r

The carriage return character. (ASCII 13)/\r/ matches a carriage return

\s

A single whitespace character/a\sb/ matches a b but not ab

\S

A single non-whitespace character/a\Sb/ matches a2b but not a b

\t

The tab character. (ASCII 9)/\t/ matches a tab.

\w

A single word character - alphanumeric and underscore/\w/ matches 1 or _ but not ?

\W

A single non-word character/a\Wb/i matches a!b but not a2b



14/01/2015

PHPExcel - Formating cell and Number Format

PHPExcel - Formating cell and Number Format

PHPExcel - Formating cell and Number Format  css formating


14/01/2015

Php $_SERVER some key value

[php] <?php $_SERVER["QUERY_STRING"] // index.php?x=1&y=2 $_SERVER["REMOTE_ADDR"] // client ip $_SERVER["HTTP_REFERER"] // http://domain.com/blog/category/11 $_SERVER["REQUEST_URI"] // /blog/category/11 $_SERVER["SCRIPT_NAME"] // index.php $_SERVER["SERVER_NAME"] // domain.com $_SERVER["HTTP_HOST"] // domain.com $_SERVER["DOCUMENT_ROOT"] // /home/username/public_html ?> [/php]

14/01/2015