List Code

Total Items found in Code is 984.
This is a collection of various code tests and descriptions on how to use them. Primarily HTML, CSS, Javascript and PHP.
php
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..

5:30 am, April 17, 2019
php
validate a url using php with FILTER_VALIDATE_URL

checks if a url is valid

11:04 pm, March 28, 2019
php
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..

12:44 am, March 22, 2019
php
calculate a percentage (dec) difference based on two numbers

this function will show you the percentage difference between two numbers

12:13 am, March 22, 2019
asp
asp classic get a url and display it

gets a url and displays it using XMLHTTP

12:08 am, March 20, 2019
css
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><..

5:10 am, March 13, 2019
php
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.

3:40 am, February 25, 2019
php
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..

12:27 am, February 11, 2019
css
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 ..

12:28 am, January 18, 2019
css
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..

4:27 am, January 16, 2019
php
Date Conversion PHP

Convert 1/1/2011 into 2011-01-01 00:00:00

10:40 pm, January 14, 2019
css
white space pre-wrap formatting

when you want to preserve line breaks in plain text without having to add br tags or p tags.

10:23 pm, January 1, 2019
php
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.

1:34 am, December 19, 2018
php
echo todays date and time in a nice format

This will produce some thing like this: 19 December 2018 @ 10:12

11:48 pm, December 18, 2018
core
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..

11:38 pm, December 13, 2018
core
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..

11:33 pm, December 13, 2018
php
Generate Sub menu using Core

11:09 pm, December 13, 2018
php
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.

12:17 am, October 30, 2018
php
human_filesize php

function via here http://php.net/manual/en/function.filesize.php#106569

5:40 am, October 29, 2018
bat
xcopy backup full directory windows bat

xcopy /y/s/e/d/c/k/r d:\photos\*.* h:\photos

10:33 pm, October 24, 2018
php
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..

3:53 am, October 24, 2018
php
sqlite check table name exists

check that the table name exists in a sqlite database, this function it taken from a class.

12:44 am, October 24, 2018
php
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..

3:37 am, October 22, 2018
html
meta keywords tag

used in the page header keywords are seperated by comma's. e.g: key word,keyword,etc

5:50 am, October 17, 2018
html
meta description tag

used in the page header

5:48 am, October 17, 2018
php
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..

5:36 am, October 17, 2018
html
favicon code meta tag

if you want to link a png as a favicon

4:01 am, October 17, 2018
php
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 ..

12:07 am, October 17, 2018
css
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.

1:22 am, October 5, 2018
php
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..

1:39 am, September 21, 2018
php
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..

1:17 am, September 21, 2018
php
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;

2:45 am, September 17, 2018
php
Get Current Page URL PHP

There is a few methods of getting this but here is a simple one. Replacing the http or https manually.  $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; Here is a more complex ..

2:19 am, September 4, 2018
php
Get the document root path in php $_SERVER['DOCUMENT_ROOT']

I ususally use this one if i am linking to files in the server document root folder rather than specifying ../directory/include.file.php i will use something like this:  $document_root = $_..

12:23 am, September 4, 2018
php
remove all of an element in a string &lt;h1&gt;

good if you want to remove all of the instances of an element in a string like if you have a <h1> tag in your string and want to remove it you can use the following code. $additional = "some te..

6:25 am, August 31, 2018
php
get text between tags

Using DOMDocument you can get strings between tags Useful if you are processing raw html files with php function getTextBetweenTags($string, $tagname){ $d = new DOMDocument(); $d->load..

6:20 am, August 31, 2018
php
sqlite basic sql and loop results

basic loop through sql results using sqlite and php $sql = "select $field_name from $db_table_name"; $out = ""; $result = $db->query($sql); if($result) { while($row = $result->fetchA..

6:20 am, August 31, 2018
php
convert all images into base64 encoded

if you have a bunch of html with inline image links this will convert them into base64 images inline. <?php $html = "my html string with multiple image tags..."; $dom = new DOMD..

6:20 am, August 31, 2018
wordpress
wordpress change domain in config, wordpress domain config

When moving wordpress sites around the place its usually easiest to change the domain like this. add these to your wp-config.php file define('WP_HOME','http://newsite.com'); define('WP_SITEURL','ht..

6:20 am, August 31, 2018
php
read and sort directory contents in php

if you need to read in the contents of a directory in php and sort it by date header('Content-Type: application/json'); $dir = "./html/"; $file_type = ".html"; $out = ""; $files_array[] = ""; ..

6:20 am, August 31, 2018
php
uniqid random string

Here is a smaller implimentation of the built in uniqid() function. Good if you want to generate smaller unique strings for url's uniqid example suniqid(5) function suniqid($len = 5) { $..

6:20 am, August 31, 2018
php
show response headers from file get contents

this will show the http_response_header when using file get contents, can be useful for seeing what the server is doing. $contents = @file_get_contents($url); echo "<pre>"; var_dump($http_re..

6:20 am, August 31, 2018
wordpress
wordpress show the page content for use in a template

if you are using page templates in wordpress and need to show content from wordpress this is the easiest method. This only works for wordpress "pages" not blog "posts". For showing blog posts you will..

6:20 am, August 31, 2018
php
file get contents reads entire file into a string

you can use the file_get_contents function to read a file or a web address usage get a url content $homepage = file_get_contents('http://www.example.com/'); echo $homepage; get a file con..

6:20 am, August 31, 2018
php
using parse_url to extract parts of a url

Category: PHP the parse_url php function will split a url into an array of url fragments $url = "http://kruxor.com/path/?argument=value#anchor"; var_dump(parse_url($url)); parse_url example ..

6:20 am, August 31, 2018
php
basic for loop

I know i always forget this so ill add it here, see if i can remember it. This should count to 10 Out 0 1 2 3 4 5 6 7 8 9 10

6:20 am, August 31, 2018
php
try catch test

try and catch example try { //enter code to catch file_get_contents($link); } catch(Exception $ex){ //Process the exception $page_content .= "Unable to process : $link"; }

6:20 am, August 31, 2018
php
tell wordpress to use the direct file method if its asking for ftp details

this usually happens if the permissions on the wordpress wp-content folder are not correct or writable. check the permissions are correct: (this is for apache, the user names might be different che..

6:20 am, August 31, 2018
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
There is a qualitative and quantitative difference between a day that begins with a little exercise, a book, meditation, a good meal, a thoughtful walk, and the start of a day that begins with a smartphone in bed.
Unknown
Random CSS Property

image-rendering

The image-rendering CSS property sets an image scaling algorithm. The property applies to an element itself, to any images set in its other properties, and to its descendants.
image-rendering css reference