Horizontally and Vertically Center a DIV with CSS…
An extremely simple solution to a surprisingly elusive problem. To perfectly center a DIV on an HTML page simply use the following approach.
Continue reading
PHP Strings and Characters
Here some simple tips to help with manipulating text, the simplest of things can be the most valuable.
First, if you only want to pull one character from a string, it’s a lot easier to use the following:
$string = 'puppy'; echo $string[0]; // p echo $string[1]; // u echo $string[2]; // p ...and so on
And here’s the basic concept behind the substr() function:
substr($string, start # [, length #])
– length is in brackets because it’s optional
Now let’s use this function to get a better idea of what it does.
$string = 'categories'; echo substr($string, 0); // 'categories' because we asked to start at the first character (which is 0 from the first example above) and goes right until end of string echo substr($string, 3); // 'egories' because started at the third character in the string and went to the end echo substr($string, -1); // 's' this is different from above because it starts at the end and goes left that number of characters echo substr($string, -3); // 'ies' echo substr($string,0,-1); // 'categorie' strips last letter off echo substr($string,3,4); // 'egor' - starts at the fourth character (remember 0 is the first) and shows 4 characters total (length) echo substr($string,1,3); // 'ate' - starts at the second character and shows 3 characters total (length) echo substr($string,1,-2); // 'ategori' because we started at the second character and also stripped off the last two with the "-2" echo substr($string,-3,-2); // 'i' since we're starting from the third character from the left and then are stripping off two characters from that with the "-2"
I sometimes use this if I only want to display a preview description rather than showing the whole large description.
$text = 'Great for home, school or travel. Wonderful gift item!'; echo substr($text,0,25).'...'; // displays "Great for home, school or..."
PHP Add Key & Value to Beginning of an Array…
So it turns out there is no built in function to add a key and value to the start of an array. There is;
array_unshift() - Prepend one or more elements to the beginning of an array.
However, this will only add a value. So the method we use is to create a new array with the key and value you wish to add to another and use;
array_combine — Creates an array by using one array for keys and another for its values.
For example:
$existingArray = array("fred" => "orange", "john" => "IsaSpy");
$array['our_key'] = "our_value";
$newArray = array_combine($existingArray, $array);
print_r($newArray);
//boom
Best Minecraft Texture Packs…
Minecraft is simply amazing.
Now im not a gamer and never intend to be, however, Minecraft is just awesome and is soo much fun ^^
Simply put, your a guy, in a world, where you can do anything you wish. The only game objective it to live your life.
You can build buildings, mine for better materials to build with or use them in your every day life, fight monsters at night (Creepers are simply epic), farm, invent, explore, adventure, you name it you can do it in Minecraft!
One of the better things about Minecraft is its ability to use different themes for your worlds called ‘texture packs’ and after much usage and research here are my favourite ones (in no particular order)…
Twitter…
Wow, really now. I didn’t think it was possible for an organization/website to be so perfect. Twitters new and updated website is truly a triumph. Beauty and Simplicity @HozzaMedia
The Honey Pot Project…
In tandem with my other post today (http://blog.hozzamedia.com/website-design/javascript/fend-off-the-bad-bots-ip-blocklist/).
The Honey Pot Project is a terrific organisation who build and manage helpful information about suspicious IP’s. There main thing is “The Honey Pot” – a deception trap designed to get bots, harvesters,spammers etc. to spam their software which can collect information on what they are doing and warn the community about them before they cause a problem.
Fend off the bad bots…
I have now discovered a few tips and tricks to fend off those bad bots, crawlers, harvesters, you name it.
First of all you need to create yourself a simple blocklist of IP’s, one IP per line, IP’s you dont want visiting your site. (hopefully HozzaMedia will be publishing our own one for public use soon)
123.567.678.9 657.387.93.2 1.1.1.14 etc
The PHP needs to be something simple like a script that checks if the users IP is in the text file and if it is, display a “No Entry Error”. Originally my script only displayed a HTML page with text along the lines of “Your IP address has been blocked from our network due to suspicious activity, you are being monitored. Continue reading
Google Currency Conversion…
Well, the api is pretty straight forward. It was found in the Currency Conversion gadget from iGoogle by http://oohhyeah.blogspot.com/2009/01/google-currency-conversion-api.html
Here is the example:
http://www.google.com/ig/calculator?hl=en&q=100EUR%3D%3FGBP
And the resposnse looks like this:
{lhs: “100 Euros”,rhs: “191.745037 British pounds”,display: “DISPLAY_FULL_PAGE”,error: “”,icc: true}
Heres how to do it in PHP
$amount = "100";
$from_Currency = "EUR";
$googleResponce = file_get_contents('http://www.google.com/ig/calculator?hl=en&q=' . $amount . $from_Currency . '%3D%3FGBP');
$googleResponce = explode(',', $googleResponce);
$numberInGBP = number_format(round(trim(str_ireplace(array('rhs: "', ' British pounds"'), '', $googleResponce[1])), 2), 2);
echo $numberInGBP;







