Prefix URL With Protocol In PHP

Here is a useful function I use in many of my applications, it will take a URL and see if it's prefixed with a protocol, if it's not then it will add the default prefix to the start of the string. This function will search for http://, https://, ftp:// and ftps://, if none of them are in the string then we add the prefix to the start of the string.

Read more...

Cache Google Web Fonts Api

Google web fonts is a huge library of free web friendly fonts you can easily use on your website. The fonts are loaded in to your website with Javascript and display by using font-family property in your CSS file. There are currently over 650 fonts in the library and they are continuing to add more. Google has an API developers can use to load the font list into your website,

Read more...

Hide WordPress Update Notice To All But Admins

When you have built your site on an open source project like WordPress one of the benefits you get is continuous updates and improvements to the core code. WordPress aims to release a couple of versions per year, when there is a new version of WordPress available to download there will be a notification bar at the top of your admin area. This notification bar will let you know that

Read more...

PHP Include All Files In A Folder

If you want to instantiate a class in PHP the class must be loaded into your application before you can use it. There are 4 ways you can load a class into your application include, include_once, require or require_once. But when you use this you must define all of the classes that you want to use in your application. Another option is to use an autoload function which will be

Read more...

Troubleshooting: Share Your Code

There are lots of times when you need to share code snippets, a good example is when you are troubleshooting a problem and need to ask for help. Instead of just explaining the problem you have to someone it's 1000 times easier to show them what the problem is. I get a couple emails a day from people asking for help with problems they are having with CSS or Javascript.

Read more...

Register Your Own Autoload Functions

PHP has a few in-built magic method __get(), __set(), __sleep(), __toString() etc. These functions are all really useful but they are not used very often in your day-to-day development, but one magic method is really useful this is the __autoload() function. This function is automatically called each time you try to instantiate a class but the class can not be found. When you normally call a class to use in

Read more...

Organise Your Github Gists With GistBox

Do you have a good way of organising and storing all your different code snippets? Because I use sublime text 3 as my code editor I used to just store all my code snippets as a snippet in sublime, this was fine if your are always working on one computer but what if you code on multiple computers? You won't be able to take all these code snippets with you.

Read more...

Center Elements With CSS

Here is a technique about how you can absolute center position an element on the horizontal and vertical in CSS. Center Images Horizontally To center something on the horizontal in CSS it's quite easy all you need to do is set the width on the element and apply an auto margin-left and margin-right on to the image. The browser will work out the exact margin on both the right and

Read more...

Check A Credit Card Number Passes Luhn Check

When you accept credit card numbers on your website you need to do a number of different validation checks on the credit card numbers the user enters. When the form is submitted you will need to check that the user has filled out the correct credit card number, expiry date and security code number. Before you send this to the bank or payment gateway for them to validate and process

Read more...

Create A Page Template For Logged In Users

There are times that you would want a page only to be accessible for users which have logged into your the WordPress user manager. Such as if you have a members only area of your website which is only for logged in users, you need to make sure that the page can not be seen by any users who haven't logged in yet. Wordpress has an inbuilt feature that allows

Read more...

1 2