Skip to content

Instantly share code, notes, and snippets.

// PHP
// Email Submit
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['text']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
@gabrysiak
gabrysiak / wp-php-replace-url.mysql
Last active August 29, 2015 14:05
Wordpress & PHP Replace URLs in DB
UPDATE `wp_options` SET option_value = replace(option_value, 'CURRENT_URL', 'NEW_URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE `wp_posts` SET guid = REPLACE (guid, 'CURRENT_URL', 'NEW_URL');
UPDATE `wp_posts` SET post_content = REPLACE (post_content, 'CURRENT_URL', 'NEW_URL');
UPDATE `wp_postmeta` SET meta_value = REPLACE (meta_value, 'CURRENT_URL','NEW_URL');
// Extend jQuery addClass function to accept callback function
var oAddClass = $.fn.addClass;
$.fn.addClass = function () {
for (var i in arguments) {
var arg = arguments[i];
if ( !! (arg && arg.constructor && arg.call && arg.apply)) {
arg();
delete arg;
}
}
<?php
namespace VerbalExpressions\PHPVerbalExpressions;
/**
* Verbal Expressions v0.1 (https://github.com/jehna/VerbalExpressions) ported in PHP
* @author Mihai Ionut Vilcu ([email protected])
* 22.July.2013
*/
class VerbalExpressions
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
function fgetcsv_PHP()
{
/*
* See if we can open a file named fgetcsv.csv in
<?php
/**
* @author Tom Gabrysiak
* @version 1.0
*
* Compares 2 random generated numbers to see if they are equal
*
* Class needs to be initialized before chaining other methods
*
* Example:
<?php
/**
* @author Tom Gabrysiak
* @version 1.2
* PDO Wrapper Class
*
* Example Usage:
*
* CONNECT:
* $db = new DB("mysql:host=localhost;dbname=db", "dbuser", "dbpass");
<?php
header("Content-Type: text/plain");
$dataIn = (object)array(
"string" => "value 1",
"array" => array(1,2,3),
"assoc" => array("cow"=>"moo","dog"=>"woof"),
"object" => (object)array("cat"=>"miao","pig"=>"oink"),
);
mysql -h DBHOST -u DBUSER -pDBPASS DBNAME < backup/data.sql
mysqldump -h DBHOST -u DBUSER -pDBPASS --single-transaction DBNAME > data.sql