Snippets for Website Development

PHP Snippets

Load CSV Into a 2-d Array Using PHP - Code shows how to load a CSV file into a two-dimensional PHP array.

Convert a PHP 2d-Array to CSV - Convert a 2-dimensional PHP array into a CSV string

Load CSV File Into PHP 1-d Array - Loads a flat csv file into a php array as a one-dimensional array.

Calculate Script Execution Time - Calculate the time it takes to execute a PHP script.

Round a PHP 2d Array by a Specified Key - Round a 2-dimensional array by a key. For example, sort array[$i][2] sorts all $i by the 2nd key.

Get the Distance Between Two Points in Latitude and Longitude - Find the distance between two sets of latitude and longitude points.

Loop for a Period of Time - Loop for a period of time, performing calculations. When specified time period has elapsed exit the loop.

Loop Structures in PHP - Illustrates several looping structures in PHP for various conditions.

Use PHP to Get the Links from an HTML Page - Get the links from an HTML page using PHP

Remove the Last Character From a PHP String - Remove the last character from a string in PHP

Determine if PHP String Contains a Substring - PHP function returns boolean true if the substring is contained in the string.

Insert an Element into a PHP Array - Insert a new element into a PHP array at a given location, reordering the array.

Get Contents of Directory in PHP - Retrieve the contents of a directory on the server and put the contents in an array.

HTML Snippets

Dynamically Load Content Without AJAX - Load content into a div without using AJAX or JQuery.

Get Map Directions on Google Maps - Get directions using Google maps. The starting location is input by the user, the ending location is a static address.

Basic HTML Template - This is the code for a basic HTML template to get a webpage started from scratch.

Open Two Pages With One Link - Opens two pages at the same time. One link click opens a new link in a new tab, while also opening the current page to a new page.

Open URL Using Button in Same or New Window - Opens a URL in either the same window or a new window.

Indent HTML text Multiple Levels - Indent HTML text multiple times or levels. Indent within indent as often as you want.

Dynamically Resize a DIV or Other HTML Element - Resize a div or any other HTML element using grips similar to a textarea.

Data Image Used as a Placeholder for Spacing - Use a transparent data-image as a placeholder for spacing, or for an overlay link or any other purpose. Loads with the page, not the server so it's fast and efficient.

Javascript Snippets

Strip HTML Tags from String - Remove all HTML tags from a string. If a user submits comments or other content, HTML tags need to be stripped in order control formatting.

Determine if String Contains Substring - This javascript function returns boolean true if the substring is contained in the string.

Javascript Equivalent to file_get_contents - This is a javascript function which mimics the php file_get_contents() function.

Split a String Into a 2-Dimensional-Array - Split a javascript string into a two dimensional array

Remove Quotes from String - Remove quotes from a string so it can be used in a csv file or any other situation where allowing quotes would cause the string to terminate prematurely.

Remove Return Characters From String - Remove return characters from a string. This is useful for sanitizing text which was input by a user.

Pass Javascript Variables to Another Page - Pass javascript variables from one page to another

Fade an Element In or Out with a Toggle - Fade an element in or out using a toggle button.

Determine if a Javascript Variable is a Number - Determine if a javascript variable is a numeric value.

Copy Text to Clipboard - Copy text from an input box to the clipboard.

Round Numbers Accurately to Specified Place Value with Javascript - Round numbers to a specific decimal place of accuracy.

Conditionally Load a Javascript File - Conditionally load a one or several Javascript files.

Determine When HTML Element Comes Into Viewport While Scrolling - Determine when an HTML element comes into view while scrolling.

Javascript Send Form With No Target - Send a form using Javascript which does not redirect the user. The form has no target and no callback, it just goes.

Random Shuffle Javascript Array - Shuffle a javascript array in random order.

Check for Mobile Phone - Javascript function to determine if the user is browsing with a mobile phone or not.

Shuffle a Javascript Array - This function shuffles an array in Javascript. It is only one line, and returns the shuffled array quickly.

Get the Date String in Milliseconds - Get the date in Milliseconds using Javascript cross-browser compatible.

CSS Snippets

CSS Button - Create a button effect on an element such as a div or span with CSS.

Adjust Image Responsive to Screen Size - Responsively adjust image size as screen size changes.

Horizontal Rule with Gradient Fade Out of Ends - Demonstrates using a horizontal rule (

Pure CSS Onclick Dropdown Menu - Create a pure CSS drop down menu with this code. Click to drop down a menu. NO javascript and no Jquery, only CSS.

Tab Menu Using CSS Only - Create a tab style menu using CSS only, no images.

Fade-in a Page or Element on Page Load - Fade in the contents of the page on load. This technique can be applied to a whole page or an element within the page.

Timer Shown by Progress Bar - Show a time delay with a progress bar using only CSS

Make Columns Break at New Paragraph - Not Within a Paragraph - Make columns break at new paragraph, not in the middle of a paragraph.

Center Image Vertically and Horizontally - Center and image within a div vertically and horizontally

Pulse An HTML Element Using CSS - Make an HTML element pulsate using CSS