Snippets

Here's some of my tips, tweaks and tuts, ranging from PHP, Linux, MySQL and more!

Snippets / HTML

Make a whole table rows a hyperlink with HTML

The other day when I was creating a new mail inbox feature for a certain website I needed to somehow make a row of information all clickable in order to take you through the full details of that particular message.

I thought there's probably a way I could do this with JavaScript but surely there was an easy way to do this with normal HTML.

The HTML

Unfortunately one drawback to this method is to have to add the same link inside every <td>, making this process slightly repetitive.

Re: Central Heating Hi John, further to our correspondence regarding the quote for the underfloor heating... 20th Jan

The CSS

In order to create the allusion that the whole row is clickable, you need to set both the <td> and the <a> the same "line-height", also set the traditional inline element <a> to display:block; and finally so there's no gaps between cells set "border-spacing" to 0

table { border-spacing: 0; padding:0; }
table td { line-height:24px; }
table td a { display:block; line-height: 24px; } 

12 years ago / Read More

Snippets / HTML

Use PHP to round up to a nearest multiple

With this handy little function you can easily round up a given number to the nearest multiple of your choice.

The function

/**
 * Round up to the nearest multiple of your choice.
 *
 * @param int $number 
 * @param int $near
 * @return int
 */
function get_nearest_multiple( $number, $near ) 
{ 
     $nearest = round($number/$near)*$near;
      
     return $nearest;
}

An example

echo get_nearest_multiple(4.7,0.5); // prints 4.5
 
echo get_nearest_multiple(4.2,0.5); // prints 4

echo get_nearest_multiple(3.9,0.5); // prints 4

12 years ago / Read More

Snippets / HTML

Encode emails to stop spam harvesting

  • Snippet Length: 5 minutes
  • Difficulty: Easy
  • Knowledge: HTML

Just a quick snippet here; there are many ways in which to make it as hard as possible for spam harvesting bots to scan for possible email addresses and store them one method is to HTML Encode each character in the mailto link.

Let us take the following email address info@example.com we can convert it with a free online conversion tool for ease.

We can then put this generated code

instead of this

info@example.com

we use this


&#105;&#110;&#102;&#111;&#064;&#101;&#120;&#097;&#109;&#112;&#108;&#101;&#046;&#099;&#111;&#109;


13 years ago / Read More