-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
Jessica Kennedy edited this page Jul 19, 2017
·
14 revisions
-- UNDER CONSTRUCTION --
- clean_number('string') - A quick function to remove and characters and letters from a string and return only the numbers, commas, and periods.
$serialnumber = clean_number('SRV293-26731-853-US170711');
$otherCountries = clean_number('1.542.765,23');
$usCurrency = clean_number('$5,235.95');
echo $serialnumber; # 29326731853170711
echo $otherCountries; # 1.542.765,23
echo $usCurrency; # 5,235.95
echo clean_number('4f32k91025'); # will output 43291025
- decimal_to_fraction(num) - A function to convert a whole number with decimal or decimal to a fraction. Currently this is limited to a denominator of 128
$dec1 = decimal_to_fraction(.5);
$dec2 = decimal_to_fraction(0.25);
$dec3 = decimal_to_fraction(5.125);
$dec4 = decimal_to_fraction(126.2578125);
echo $dec1; # 1/2
echo $dec2; # 1/4
echo $dec3; # 5 1/8
echo $dec4; # 126 33/128
echo decimal_to_fraction(0.125); # 1/8
- fraction_to_decimal('string') - A function to convert a fraction to a decimal.
$frac1 = fraction_to_decimal('1/2');
$frac2 = fraction_to_decimal('1/4');
$frac3 = fraction_to_decimal('5 1/8');
$frac4 = fraction_to_decimal('126 33/128');
echo $frac1."<br />"; # 0.5
echo $frac2."<br />"; # 0.25
echo $frac3."<br />"; # 5.125
echo $frac4."<br />"; # 126.2578125
echo fraction_to_decimal('1/8'); # will output 0.125
- is_whole_number(num) - Returns TRUE if the number does not contain a string, character, or decimal
# numbers may be passed as string or float
$numbers = array(2, 2.1, 2.5, 2.9, '3', '3.1', '3.6', '3.9', 4, 5, 6.1, 6.3, 7, 7.3, 7.5, 8);
foreach ($numbers as $num) {
if (is_whole_number($num) {
echo $num.'is a whole number';
}
else {
echo $num.'is not a whole number';
}
}
Example 2:
echo (is_whole_number(12.53) ? "TRUE" : "FALSE"); # will output FALSE
echo (is_whole_number(45) ? "TRUE" : "FALSE"); # will output TRUE
- return_while_number(num) - Returns only the whole number of a decimal number
echo return_whole_number(45.34); # will output 45
- return_deciaml_number(num) - Returns only the decimal portion of the number
echo return_decimal_number(45.34); # will output 0.34
- ordinalize(num) - Converts the number to string and adding st, nd, rd, or th to the number
echo ordinalize(3); # will output 3rd
- parity(num) - returns the parity of a number
echo parity(3); # will output 0
- getDistanceBetweenPoints(lat1, long1, lat2, long2) - Returns an array of the calculated a birds shot distance
echo getDistanceBetweenPoints(39.103119, -84.512016, 36.850769, -76.285873); # Example is Cincinnati, OH to Norfolk, VA -- will output Array
Array (
[miles] => 474.044402345
[feet] => 2502954.44438
[yards] => 834318.148127
[kilometers] => 762.900514648
[meters] => 762900.514648
)
getAddressFromPoints(lat, long) - Returns nearest address from points
echo getAddressFromPoints (39.103119, -84.512016)# Example is Cincinnati, OH -- will output Array
Array (
[formatted_address] => 609 Walnut St, Cincinnati, OH 45202, USA
[street_number_long] => 609
[street_number_short] => 609
[street_name_long] => Walnut Street
[street_name_short] => Walnut St
[street_type] => route
[city_name_long] => Cincinnati
[city_name_short] => Cincinnati
[county_name_long] => Hamilton County
[county_name_short] => Hamilton County
[state_name_long] => Ohio
[state_name_short] => OH
[country_name_long] => United States
[country_name_short] => US
[zipcode_long] => 45202
[zipcode_short] => 45202
[zipcode_ext_long] => 1191
[zipcode_ext_short] => 1191
)
AddressToPoints('string') - Determines best possible solution to address and returns the latitude and longitude of address given.
echo AddressToPoints ('10 Fountain Square, Cincinnati, OH 45202')# will output 39.1019474, -84.5123371
days_month('$month', '$year') - Will return the total number of days in a given month, if year is omitted, it will return the days for the current year.
echo days_month('2', '2014'); # will output 28
echo generate_calendar('2017', '01'); # will output
/*
January 2017
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
*/
echo minutestohours(494); # will output 08:14
echo _ago(45); # will output 4 decades
# Notice how remaingTime() will automatically reduce the time in the output:
echo remainingTime(date('Y-m-d', strtotime('+5 years +4 month +2 weeks +5 days +18 hours +43 minutes +31 seconds')));
# will output 5 years 4 months 3 weeks 21 hours 59 minutes 56 seconds remaining
echo secstostr(269); # will output 4 minutes 29 seconds
echo string_continue('Today is the day for all good men to come to the aid of their country.', 30); # will output Today is the day for all...
echo string_trim('Today is the day for all good men to come to the aid of their country.', 5); # will output Today is the day for...
echo string_mid_trim('Today is the day for all good men to come to the aid of their country.', 30); # will output Today is the[...]their country.
echo random_passwd(12); # will output yJiqJReSxM34
echo pluralize(3, 'box', 'boxes'); # will output boxes
makeLink()
getCloud()
isemail()
echo encode_email('jessica@jbrowns.com'); # will output Contact Us
echo highlighter_text('Today is the day for all good men to come to the aid of their country', 'good men');
# NOTE: "good men" will be bold and blue
# will output Today is the day for all good men to come to the aid of their country
qr_code()
wordMatch()
getIP()
zip()
unzip()
get_client_language()
strip_xss()
safe_redirect()
autoglobals()
hitcounter()
resize_image()
show_gravatar()
Hex2RGB()
values2keys()
strReplaceAssoc()
is_numeric_array()
array_changecase()
SQLclean()