Skip to content

Instantly share code, notes, and snippets.

@lcherone
lcherone / gist:67039196dadafacf33c7
Last active August 29, 2015 14:00
Curl multi function GET snippet
<?php
function curl_multi($urls = array()) {
$curl = array();
$result = array();
$mh = curl_multi_init();
foreach ($urls as $id=>$url) {
$curl[$id] = curl_init();
curl_setopt($curl[$id], CURLOPT_URL, $url);
curl_setopt($curl[$id], CURLOPT_HEADER, 0);
<?php
session_start();
/**
* Simple OMC pool API class
*
* @author Lawrence Cherone
* @version 0.01
*/
class omc{
@lcherone
lcherone / gist:f5a3d4859c0d11cba868
Last active August 29, 2015 14:00
http://mattsmines.net/ OMC pool API class (With curl_multi example)
<?php
session_start();
/**
* Simple OMC pool API class
*
* @author Lawrence Cherone
* @version 0.01
*/
class omc{
@lcherone
lcherone / gist:6f8043447f7f0099d430
Created May 3, 2014 18:38
Swere words for swear_filter function
*damn
*dyke
*fuck*
*shit*
4r5e
5h1t
5hit
@$$
a55
ahole
<?php
/**
* Swear word filtering function, requiers a list of words,
* Second parameter reveals *n letters
*
* @wordlist https://gist.github.com/lcherone/6f8043447f7f0099d430
*
* @param string $str
* @param int $reveal
* @return string
@lcherone
lcherone / gist:ffee79694aefee1bf28e
Created May 3, 2014 20:06
HTTP Request Class to rebuild RAW request from $_SERVER
/**
* Access the HTTP Request
*
* Found on http://www.daniweb.com/web-development/php/code/216846/get-http-request-headers-and-body
*/
class http_request {
/** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */
public $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH');
<?php
date_default_timezone_set('Europe/London'); // Set this to your local timezone - http://www.php.net/manual/en/timezones.php
/**
* The root directory where the repos live.
*
* @var string
*/
$root_dir = '/your/root/dir/';
@lcherone
lcherone / gist:3285cbf0fc8574967f6f
Last active August 29, 2015 14:01
de'BBCODE'er
<?php
function bbdecoder($bbcode){
/* Match url */
$urlmatch = "([a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_:]+\\.+[A-Za-z0-9\.\/%&=\?\-_:]+)";
/* Basically remove HTML tag's functionality */
$bbcode = htmlspecialchars($bbcode);
/* Bold text */
$match["b"] = "/\[b\](.*?)\[\/b\]/is";

Obligatory suggestion, Don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

You should change the function name to get_total hits, as it makes no sense, and the scope of the database connection wont be available within functions, your need to pass it to it or use global to access it, this makes it bad practice but for example

<?php 

function get_total_hits(){
	global $db; // or whatever the variable for mysql_connect() is
@lcherone
lcherone / GitDeploy.php
Last active August 29, 2015 14:04
Git Deployment PHP class
<?php
// Set your local timezone - http://www.php.net/manual/en/timezones.php
date_default_timezone_set('Europe/London');
/**
* Git Repo Deploment class.
* @version 1-2
* @author (original) arindambiswas <http://www.collectivezen.com>
* @link https://gist.github.com/arindambiswas/4634fff09b3ad4e4bf48
*