Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / array-to-simplexml.php
Created November 4, 2012 16:40
Convert/Import an Array into a SimpleXMLElement
/**
* Convert/Import an Array into a SimpleXMLElement
*
* @author hakre <http://hakre.wordpress.com/>
* @see http://stackoverflow.com/a/13219372/367456 for usage examples
*/
class SimpleXMLArrayImport
{
const TYPE_INVALID = 0;
const TYPE_EMPTY = 1;
@hakre
hakre / PharPath.php
Created November 1, 2012 20:12
Some knowledge about a phar path condensed into a class
<?php
/**
* Some knowledge about a phar path condensed
* into a class
*/
class PharPath
{
private $path;
@hakre
hakre / datetime-ranges.php
Created October 30, 2012 00:49
DateTime Range and Ranges
<?php
/**
* @link http://stackoverflow.com/questions/13129336/split-a-time-range-into-pieces-by-other-time-ranges
* @link https://gist.github.com/gists/3977645
* @author hakre
*/
class Range
{
@hakre
hakre / mysqli-example.php
Created September 21, 2012 10:31
Mysqli Database Connection Example
<?php
/**
* @link http://stackoverflow.com/questions/12493927/build-a-mysqli-db-connection-class-and-other-classes-use-it
*/
//// for example this could be config-database.php ////
define('DB_HOST', 'localhost');
define('DB_USER', 'testuser');
define('DB_PASS', 'test');
define('DB_NAME', 'test');
@hakre
hakre / iteration-and-recursive-iteration.php
Created September 2, 2012 14:26
Iteration and Recursive Iteration Examples Code
<?php
/*
* Iteration and Recursive Iteration Examples Code
*
* @link http://stackoverflow.com/questions/12077177/how-does-recursiveiteratoriterator-works-in-php
* @author hakre <http://hakre.wordpress.com>
*/
### To have these examples to work, a directory with subdirectories is needed,
### I named mine "tree":
@hakre
hakre / DomTree.php
Last active February 22, 2021 11:40
DomTree - Dump DomDocument based documents, suiting debugging needs
<?php
/**
* DomTree
*
* Dump DomDocument based documents, suiting debugging needs
*
* @author hakre <http://hakre.wordpress.com/>
* @link http://stackoverflow.com/questions/26321597/getting-price-from-amazon-with-xpath/26323824#26323824
* @link http://stackoverflow.com/questions/12108324/how-to-get-a-raw-from-a-domnodelist/12108732#12108732
* @link http://stackoverflow.com/questions/684227/debug-a-domdocument-object-in-php/8631974#8631974
@hakre
hakre / tutorial-function.md
Created August 8, 2012 16:01 — forked from PeeHaa/tutorial-function.md
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 are used to group code into something useful, it organizes your code.

Generally speaking a function is a piece of code with an input, some defined actions based on the input and an output and then an optional return value:

INPUT --> PROCESSING --> OUTPUT

A function therefore is a little program inside a larger program. It sometimes is called subroutine as well because of that.

@hakre
hakre / xpathr.php
Created July 27, 2012 08:48
html to xml webservice example
<?php
/**
* Load a Remote Resource as HTML Document, run XPATH query and return the resulting
* XML
*/
function array_default($array, $name, $default = NULL)
{
return isset($array[$name]) ? $array[$name] : $default;
}
@hakre
hakre / gist:3184468
Created July 26, 2012 20:57 — forked from rlemon/gist:3183650
Gitnologist
Fork it, use it, break it, fix it,
Comm it, push it, pull - request it,
Fetch it, branch it, patch it, fake it,
Merge it, ssh it, never - https it.
Write it, cut it, paste it, save it,
Build it, check it, quick - rewrite it,
Clone it, crack it, crop it, comp it,
Drag and drop it, gzlib - gzip it.
@hakre
hakre / DateInterval_11556731.php
Created July 19, 2012 09:12
How we can add two date intervals in PHP
<?php
/**
* How we can add two date intervals in PHP
* @link http://stackoverflow.com/q/11556731/367456
* @link http://codepad.viper-7.com/oBW2le
*
* NOTE: This code is rough.
*/
header("Content-Type: text/plain;");