PHP Snippets

Total lessons: 28

Get Keyword Frequency In PHP

In this tutorial we're going to find out how we can get the keyword frequency from a string or even a webpage in PHP. This information is useful when you're trying to work out the SEO of a page so you...

Sanitize Special Word Characters With PHP

Anybody who has worked with user content on a website will know the problem you get when a user writes the content in Word and copy and pastes this content into a textarea so that you can store it in...

Convert Image To Data URI With PHP

One of the easiest ways to speed up your page loading times is to reduce the amount of HTTP requests that your website makes, each time your webpage needs to fetch an external resource such as a CSS s...

Get Image Src With PHP

There are some occasions where you need to get the attribute value in PHP from a HTML element, this can be for migration reasons or perhaps you are writing a script to scrap a website to store the val...

File_Exists For Remote URL

If you want to make sure that a file exists in PHP you can use the function file_exists(), which takes one parameter of the filename. // Returns true if the file exists file_exists( $filename ); Thi...

Calculate Different Shades Of A Colour

There are different ways colours are defined the two most popular values in web are HEX or RGB. Both of these values have a logical formula to working out what colour each value means, because of this...

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. Thi...

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 y...

Force Browsers To Load Latest CSS And JS

In modern browsers they will cache most external aspects of the website, they will cache all images and even stylesheets and javascript files of your website. During a website redesign where you can c...

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, requi...

Store HTML View File In A Variable

If you have used a MVC language before you would be familiar with the practice of separating your business logic from your HTML. The way this works in MVC language is that the framework will allow you...

Resize Image Class With PHP

A common feature that you will across in websites is the ability to resize an image to fit an exact size so that it will displayed correctly on your design. If you have a very large image and you are...

Encode Email Addresses With PHP

Spam bots will crawl your pages exactly the same way Search Engines crawls your pages, but while Search Engines are crawling to index your content, spam bots are crawling to find certain information....

How To Use PHP To Get Visitors Browser

With the raise of popularity in using mobile devices to access websites, web designers need to start designing their websites so it can be used correctly on a mobile device. There are several ways you...

Easily Create A Table In PHP

Here is a small PHP snippet to easily create a table in PHP. First create the draw_table function.