Skip to content

Instantly share code, notes, and snippets.

@aswebdev
aswebdev / PHP Loop Directory Function
Created October 30, 2013 23:11
Function that Loops files in a directory and puts them into an array
// Loop Directory Function
function loopDirectory($path,$filetypes='',$stringmatch='') {
// initiate the variables
$array = array();
$error = '';
// check if $filetypes is set, if so and not an array make an array
if((!empty($filetypes)) && (!is_array($filetypes))) {
$filetypes = array($filetypes);
}
@aswebdev
aswebdev / PHP Database Select Function
Last active December 27, 2015 00:59
A Database select function
function dbSelect($select,$from,$where,$orderby=false,$limit=false,$connection=false) {
// dbSelect 0.2, Created by AS
// General Database Selection Function
// initate variables
$query = ''; // String to Setup query
$return = ''; // The return array
$rowsReturned = ''; // The Number of Rows Returned from the query
$error = false; // Boolean. Has an error.
@aswebdev
aswebdev / Encrypt and Decrypt Functions with salt
Created October 30, 2013 23:14
Functions for securely encrypting data with Salt
function encrypt($key,$string) {
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
}
function decrypt($key,$encrypted) {
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
}
@aswebdev
aswebdev / SQL Replace Query
Created October 30, 2013 23:15
An SQL Query that will search and replace
UPDATE `categories` SET url = REPLACE(url,"fromstring","tostring")
@aswebdev
aswebdev / JavaScript function for validating an integer
Created October 30, 2013 23:16
JavaScript integer validation function
function isNumber(n) {
// Determine if numeric (whole number or float)
return !isNaN(parseFloat(n)) && isFinite(n);
}
@aswebdev
aswebdev / Update Mac Apache Virtual Hosts
Last active December 27, 2015 10:49
Access Mac Apache Virtual Hosts & Update Host Settings
# Access Mac Virtual Hosts
vi /private/etc/apache2/extra/httpd-vhosts.conf
# Creating a New Virtual Host
Directory "/Users/andrew/Documents/ASCMS/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
DocumentRoot "/Users/andrew/Documents/ASCMS/"
@aswebdev
aswebdev / PHP SEO Friendly URL Function
Last active December 13, 2018 03:56
Creates an SEO Friendly URL from a string
// SEO Friendly Filter Function
function seoUrl($string) {
$string = trim($string); // Trim String
$string = strtolower($string); //Unwanted: {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string); //Strip any unwanted characters
@aswebdev
aswebdev / Post to Page JavaScript Function
Last active December 27, 2015 23:29
JavaScript function to POST object data to a URL
// Post to Page Function
function postToPage(url,data) {
// Setup Form Object
var f = document.createElement("form");
f.setAttribute('method',"post");
@aswebdev
aswebdev / PHP Create HTML Email
Last active December 28, 2015 18:09
Function for creating HTML emails in PHP
function createEmail($to,$from,$subject,$content,$cc=false,$bcc=false) {
$headers = "From:$from\r\n";
$headers .= "CC:".$bcc."\r\n";
$headers .= "BCC:".$bcc."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
@aswebdev
aswebdev / Filename Append
Last active August 29, 2015 13:56
Append an append string to a filename
// Append to a filename
function appendToFilename($file,$append) {
return preg_replace('/(\.[^.]+)$/', sprintf('%s$1', $append), $file);
}