List Code
for loop with a 5 increment
$css_out = "";$max_width = "50";for($i=0; $i<=$max_width; $i = $i + 5) {$css_out .= ".m".$i."{margin:".$i."px;}";}return $css_out;
replace anything in brackets in a string using preg_replace regex php
Lets say we have a string like this hi there im a string (not really a string). and we want to remove this bit (not really a string) We can do this using the following regex (preg_replace) $strin..
Regular expression breakdown regex preg_replace php
/ - opening delimiter (necessary for regular expressions, can be any character that doesn't appear in the regular expression \( - Match an opening parenthesis [^)]+ - Match 1 or more character that..
css :active pseudo-class usage
The :active selector is a CSS pseudo-class. It represents an element that is being activated by the user when they are interacting with a button or link.
generate a random color rgb code with php
this code will generate a random color every time its loaded using the rand function in php and generate something like this. .random-color { color:rgb(111,222,111); } PHP Code <?php ..
favicon code meta tag
if you want to link a png as a favicon
assign array to variables in a loop
this will assign all items in the array to variables $p1,$p2.. etc. $p = "/1/2/3/4/5/"; $page_array = explode("/",$p); foreach ($page_array as $key => $value) { if($value > "") { ${"p".$pc..
meta description tag
used in the page header
meta keywords tag
used in the page header keywords are seperated by comma's. e.g: key word,keyword,etc
get current class name with get_class
This will return the current class name, can be used in side a function of the current class object or give it another object name to return. class myclass {function myfunction() {echo get_class($thi..
sqlite check table name exists
check that the table name exists in a sqlite database, this function it taken from a class.
for loop set variables $p1,$p2.. etc as blank - variable variables
this will loop through and assign the variable $p1 = ""; to each in the loop so it appends the loop number to the variable name so you end up with $p1 = "value"; $p2 = "value2"; etc, rather than h..
xcopy backup full directory windows bat
xcopy /y/s/e/d/c/k/r d:\photos\*.* h:\photos
human_filesize php
function via here http://php.net/manual/en/function.filesize.php#106569
page load timer class
usage: $page_timer = new page_timer; // at the start of your code echo $page_timer->end(); // at the end of your code.
Core Class - Basic Core Structure
A Core class that can be used as a base for all content types and uses the extend classes to define the database variables. So basically you can set up core class and then create sub extend classes to..
Core - File Structure
Core works on the following directory structure: //class//class/extends//css//db//images//import//inc//lib//pages//templates/ all of the core structure is fairly self explanitory core.class.php can..
echo todays date and time in a nice format
This will produce some thing like this: 19 December 2018 @ 10:12
Generate a random title from an array
give this an array of strings and it will pick a random one to return from the array.
white space pre-wrap formatting
when you want to preserve line breaks in plain text without having to add br tags or p tags.
Date Conversion PHP
Convert 1/1/2011 into 2011-01-01 00:00:00
Using Flexbox rather than Floats
So i was still using float left for a bunch of elements i was working on the other day, sometimes it's hard to drop old techniques. What are the actual benefits of using flexbox rather than float lef..
image Checkbox Replacement for Forms
Some sites like to be a bit tricky and have some complicated form checkbox replacement which is not all that hard, just can be a bit annoying as you have to extract the images for this to work. Demo ..
How Many Days Since a Date and other Calculations
Here i calculate the number of days since a certain date in php and use the values for checking how much something costs per day. Start Date Lets add the date that the item was purchaced. In d..
PHP MySQL vs SQLite Count Items Function
I have been writing a few functions using sqlite and mysql. There are a couple of slight differences which can be seen in this count items_function.
Using nth-child css to hide list items or repeated elements
Lets say that i have a list like this: <div class='my-awesome-list'><div class='a-list-item'>yay im a list item</div><div class='a-list-item'>yay im a list item</div><..
asp classic get a url and display it
gets a url and displays it using XMLHTTP
calculate a percentage (dec) difference based on two numbers
this function will show you the percentage difference between two numbers
function to create a uid from html
this function converts a html string into a uid or unique id type string, its not actually unique, but its a string that can be used to make the title of something that contains html into a usable str..
validate a url using php with FILTER_VALIDATE_URL
checks if a url is valid
Cut a string when it finds a certain character with PHP
ok so lets say we have a string like this: Hi there im a string. I am also part of the same string. And we want to shorten the above string into just: Hi there im a string. This is what i wo..
create a mysql or sqlite current timestamp with php
just in case you need to create a CURRENT_TIMESTAMP using php, this formats the current date into the following.
using the disk free space function in php
here is a built in php function that will show the amount of free space available on your server.
Drop Down Menu Swapping Left align to Right
this is useful if you have a nav that hits the right side of the screen and you want it to open on the left rather than the right side. you can see on the very right drop down item opens with its item..
Change link target with JQuery
this will change the link href target to # on document load rather than its original link
Dropdown Box with Searchable Text
Here we have a dropdown select box, that you can type into to search the available options. No Javascript Required for this the browser does all the work. Press into the text box, and you will see a..
Applied Accessibility - Screen reader only css
This is how a screen reader only css markup can be added. The content will still be available to screen reader clients.
Applied Accessibility - Access Keys
Access keys can be applied to link elements and in chrome you can access them by pressing ALT+ SHIFT + [accesskey] for some reason when testing this in chrome the a key was not accessible, but g and ..
Applied Accessibility - Tab Index
using the tabindex property on elements allows you to press the tab key while on the page and tab through the elements depending on the order specified by the tabindex. tab index can be applied to man..
Making an image responsive using css
the following css will make an image display 100% its size and keep its aspect ratio if the screen size or element size gets smaller than the containing image. you should be able to drag the edge of t..
Making Images Retina Display Friendly
Have you ever noticed images look a bit blurry on your high res screen? Sometimes this is referred to as a "Retina" display... Its probably because the image used is exactly the pixels made for a regu..
Viewport width and height calculations
Rather than using px and em you can also use the vw and vmin to resize elements which depend on the width and height of the display.
using flexbox to align elements in a row
flexbox is so good at aligning elements, yes i used to use float left and then percentages and overflow auto or hidden the surrounding div, but now with flex you can just do something like this.
flex shorthand css
flex can be short handed under the flex property. For example, flex: 2 0 20px; will set the item to flex-grow: 2;, flex-shrink: 0;, and flex-basis: 20px;. The following class examples both do the sa..
CSS Grid - Basic Columns
Here is a basic demo showing the usage for css grid columns. You just need to add the display:grid property and then add the grid-template-columns: adding the size of each column, adding a value for e..
Random string generator function in php suniqid
Here is a a smaller version of the built in php function uniqid() uses letters and numbers and specify the length of the random string.