function locate_country ($country
{
$data = file_get_contents"http://maps.google.com/maps/geo?output=csv&q="urlencode$country));
$arr = explode",", $data);
if (count$arr)>=4) {
if ($arr[0]==200) {
return array'latitude'=>$arr[2], 'longitude'=>$arr[3]);
} else {
throw new Exception'Country could not be geocoded');
}
} else {
throw new Exception'Country could not be geocoded');
}
}
Tag: Math
eXorithm – Execute Algorithm: Discuss Algorithm hailstone
hailstone    version 0.3    Calculates a hailstone sequence.http://en.wikipedia.org/wiki/Collatz_conjecture
There are no comments yet
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm stock_ticker
stock_ticker    version 3.2    Generate an HTML stock ticker with current quotes.Subject: Insted CSV file can we call json file
suhas | posted: Aug 21, 2012 12:50 pm | [reply] |
insted CSV file can we call json file for the ticker, can we use same method?
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm check_domain
check_domain    version 0.1    Check a domain name against a whitelist and blacklist.
There are no comments yet
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm sort_multi_array
sort_multi_array    version 0.1    Sort a two-dimensional array by one (or more) of the elements in the nested arrays. Accepts a variable number of arguments.Subject: Usage Example for sort_multi_array would be useful
optionzz | posted: Jan 2, 2014 08:02 pm | [reply] |
I have a TOUGH time wrapping my head around the strange php array design. All I need to do is use a matrix with numeric indexes for each dimension. Somehow, EVERY example uses names for the "columns" in the second index. If I want that, I’ll use SQL.
Sorry, complaining won’t help. I’d love to see how this would work for a normal 2 dim array like
0 1 2 3
0 (0,0) (0,1) (0,2) (0,3)
2
4 (4,0) (4,1) (4,2) (4,4)
I want to sort all 5 rows based on any of the column NUMBERS (there are no names).
I’m pretty new to PHP but not to programming. Perhaps someone could help break the logjam in my head that REFUSES to understand arrays inside arrays with names instead of numbers, but most importantly, how to make the sort work!
Thanks.
Subject: Usage Example for sort_multi_array would be useful
optionzz | posted: Jan 2, 2014 07:58 pm | [reply] |
I have a TOUGH time wrapping my head around the strange php array design. All I need to do is use a matrix with numeric indexes for each dimension. Somehow, EVERY example uses names for the "columns" in the second index. If I want that, I’ll use SQL.
Sorry, complaining won’t help. I’d love to see how this would work for a normal 2 dim array like
0 1 2 3
0 0,0 0,1 0,2 0,3
1 1,0 1,2…
New Comment
eXorithm – Execute Algorithm: View / Run Algorithm invert_image
function invert_image ($image
{
$image_width = imagesx$image);
$image_height = imagesy$image);
// if the image is not true color, make it so
if (!imageistruecolor$image)) {
$image2 = imagecreatetruecolor$image_width, $image_height);
imagecopy$image2$image,0,0,0,0,$image_width$image_height);
$image = $image2
}
// loop through all the pixels
for ($h = 0; $h < $image_height; $h++) {
for ($w = 0; $w < $image_width; $w++) {
// get the color at this pixel
$color = imagecolorsforindex$image, imagecolorat$image, $w, $h));
// invert the color
$color'red'] = 255 - $color'red'];
$color'green'] = 255 - $color'green'];
$color'blue'] = 255 - $color'blue'];
// create the new color
$new_color = imagecolorallocate$image, $color'red'], $color'green'], $color'blue']);
// set the color
imagesetpixel$image, $w, $h, $new_color);
}
}
return $image
}
eXorithm – Execute Algorithm: Discuss Algorithm magic8ball
magic8ball    version 0.2    Ask the magic 8 ball your question.Subject: magic8ball
Haldan | posted: Feb 22, 2012 04:57 am | [reply] |
function magic8ball() {
$answers = array(‘It is certain’, ‘It is decidedly so’, ‘Without a doubt’,
‘Yes â definitely’, ‘You may rely on it’, ‘As I see it, yes’,
‘ Most likely’, ‘Outlook good’, ‘Signs point to yes’, ‘Yes’,
‘Reply hazy, try again’, ‘Ask again later’,
‘Better not tell you now’, ‘Cannot predict now’,
‘Concentrate and ask again’, ‘Dont bet on it’,
‘My reply is no’, ‘My sources say no’, ‘Outlook not so good’,
‘Very doubtful’ );
$index = rand(0, count($answers));
return ($answers[$index]);
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm unique_image
unique_image    version 0.3    Generate a pseudo-unique "hash" image based on a string.
There are no comments yet
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm draw_cube
draw_cube    version 0.8    Draw a 3d cube.
There are no comments yet
New Comment
eXorithm – Execute Algorithm: Discuss Algorithm sum_list
sum_list    version 0.1    Sum up the numbers in an array.
There are no comments yet
New Comment