Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
#!/usr/bin/env php | |
<?php | |
$app = function($request) { | |
$body = <<<EOS | |
<!DOCTYPE html> | |
<html> | |
<meta charset=utf-8> | |
<title>Hello World!</title> |
# coding: utf-8 | |
require 'sinatra' | |
set server: 'thin', connections: [] | |
get '/' do | |
halt erb(:login) unless params[:user] | |
erb :chat, locals: { user: params[:user].gsub(/\W/, '') } | |
end | |
get '/stream', provides: 'text/event-stream' do |
Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
<?php | |
// Sets the error handler to check the current class for the value if it's missing | |
// http://stackoverflow.com/a/2669273/99923 | |
error_reporting(E_ALL); | |
ini_set("display_errors", 0); | |
class View { | |
function display($file, $values) | |
{ |
<?php | |
$validator = new Validator(); | |
// Each validation rule is a property of the validator object. | |
$validator->username = function($value, $key, $self) | |
{ | |
if(preg_match('~\W~', $value)) | |
{ | |
return 'Your username must only contain letters and numbers'; |
A very basic regex-based Markdown parser. Supports the
following elements (and can be extended via Slimdown::add_rule()
):
<?php | |
class QueryBuilder implements IteratorAggregate | |
{ | |
private $conn; | |
private $parts = array(); | |
public function __construct(Connection $conn) | |
{ |
#!/bin/bash | |
# Amazing static site generator | |
# Works for PHP and HTML sites | |
# Assumes web root to be in /web | |
# Dumps the site into a directory named "static" | |
PORT=9999 | |
php -S localhost:$PORT -t web >/dev/null & | |
PID=$! |
<?php | |
const ✓ = true; | |
const ✕ = false; | |
function ≠($left, $right) { | |
return $left != $right; | |
} | |
function ≅($left, $right) { |