Skip to content

Instantly share code, notes, and snippets.

@PeeHaa
PeeHaa / gist:6103398
Created July 29, 2013 10:17
Crap PHP tutorials
- http://www.phptutorialforbeginners.com/2012/10/php-simple-login-form-php-tutorial-for.html
@PeeHaa
PeeHaa / xpath_match_all
Last active December 11, 2015 04:38 — forked from gooh/xpath_match_all
<?php
function xpath_match_all($query, $html = '')
{
static $dom;
static $xpath;
static $content;
if (!$dom) {
$dom = new DOMDocument;
}
@PeeHaa
PeeHaa / so-chat-default-pinned.md
Created November 26, 2012 10:48
Stackoverflow PHP chat default pinned message
cv-pls: [Backlog](http://cvbacklog.gordon-oheim.biz/) ([mirror](http://cvbacklog.herokuapp.com/)) | [Meaning](http://gist.github.com/1689430) | [Chrome/Firefox Addon](https://github.com/cv-pls/) | [Cat Content](http://goo.gl/i04rR) | Snippets: [Mysql](https://gist.github.com/3881905) | Reference: [Errors](http://stackoverflow.com/q/12769982/367456) | [Operators](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php)

cv-pls: Backlog (mirror) | Meaning | Chrome/Firefox Addon | Cat Content | Snippets: Mysql | Reference: Errors | Operators

@PeeHaa
PeeHaa / pdo.php
Created September 14, 2012 17:23
PDO
<?php // always use full php tags
//require 'connect.inc.php';
$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// mysql_* function?? Eeeeek
function query($query)
{
@PeeHaa
PeeHaa / arrays.md
Created August 31, 2012 13:34
If I see one more question about arrays in PHP...

Arrays can be seen as lists which can hold information. Arrays in PHP can holds all types of values like scalar values, objects or even other arrays.

Declaring an initializing arrays

First lets see how we can declare an empty array:

<?php
$theArray = array();
@PeeHaa
PeeHaa / ol.md
Created August 27, 2012 15:52
numbered lists
  1. test 1
  2. test 2
@PeeHaa
PeeHaa / troubles.md
Created August 8, 2012 22:33
soundcloud api troubles
<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

}

@PeeHaa
PeeHaa / oauth1-sign.php
Created August 1, 2012 13:42
Oauth 1a signature example
<?php
/**
* Implementation of the oAuth1 signature spec: http://oauth.net/core/1.0a/ *
*/
namespace Oauth1\Signature;
class TwitterSignature implements \Oauth\Signature
{
protected $signatureAlgorithm;
protected $httpMethod;
@PeeHaa
PeeHaa / tutorial-function.md
Created July 30, 2012 14:25
function for tutorial

Functions

PHP already has a lot of [built-in functions][builtin-functions]. Besides the built-in functions already provided by PHP it is also possible to define your own functions. Functions can be used to run the same code multiple times without having to add the code multiple times. It can also be used to organize your code. Generally speaking a function is a piece of code with an input, some defined actions based on the input and an output. An example of function that calculates the differences in the age of two people is:

function getAgeDifference($age1, $age2)
{
    return abs($age1 - $age2);
}