Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* php array to xml conversion even for nested data
*
* @link http://stackoverflow.com/q/14136714/367456
* @see http://stackoverflow.com/a/14143759/367456 for description
* @author hakre <http://hakre.wordpress.com/credits>
*/
$array = [
@hakre
hakre / output.txt
Last active December 10, 2015 11:58
# Supported Functions:
mysql_connect().................: Supported
mysql_pconnect()................: Supported
mysql_close()...................: Supported
mysql_select_db()...............: Supported
mysql_query()...................: Supported
mysql_unbuffered_query()........: n/a
mysql_db_query()................: n/a
@hakre
hakre / lNRGXC.php
Created January 1, 2013 21:27
Codepad Viper Remote Image Viewer - http://codepad.viper-7.com/lNRGXC/55dev?
<?php
/**
* Codepad Viper Remote Image Viewer
*/
$url = 'http://i.stack.imgur.com/Pa9s3.png';
if (isset($_GET['g'])) $url = $_GET['g'];
echo '<table border="1"><tr><th colspan="3"><a href="', htmlspecialchars($url), '">', htmlspecialchars($url), '</a></th></tr>';
@hakre
hakre / gist:4426953
Last active December 10, 2015 11:19
Sample single-line XML File
<?xml version="1.0" encoding="UTF-8"?>
<response><status><version>4.2</version><code>0</code><message>Success</message></status><songs><song><tracks><track><foreign_release_id>spotify-WW:release:35dJsQDEr549O5DTFUy3uM</foreign_release_id><catalog>spotify-WW</catalog><foreign_id>spotify-WW:track:2u02eLj96Atd6TBxkH9YvN</foreign_id><id>TRYJFDJ1338646B794</id></track><track><foreign_release_id>spotify-WW:release:4bUUD51RuaeszLjN3PDd7F</foreign_release_id><catalog>spotify-WW</catalog><foreign_id>spotify-WW:track:69idM1oJ3K2Xvv0NWyJS9M</foreign_id><id>TRDCOZR133A3CA331F</id></track><track><foreign_release_id>spotify-WW:release:6UHhmTLl9T1scRYLmpHcDX</foreign_release_id><catalog>spotify-WW</catalog><foreign_id>spotify-WW:track:08Bfk5Y2S5fCxgxk371Eel</foreign_id><id>TRFVQLU1338645C5A4</id></track><track><foreign_release_id>spotify-WW:release:3SA9lShm1rzFIsUd56GhT5</foreign_release_id><catalog>spotify-WW</catalog><foreign_id>spotify-WW:track:5VWTuwU4yQ6ATUPrX7hOsN</foreign_id><id>TRTZNFF13386461DA1</id></track><track>
@hakre
hakre / tagsoup.php
Created December 30, 2012 20:52
Some very rudimentary Tagsoup Example
<?php
/**
* Tagsoup
*/
class Tagsoup
{
const NODETYPE_COMMENT = 1;
const NODETYPE_TEXT = 2;
const NODETYPE_STARTTAG = 3;
@hakre
hakre / output-buffer-to-temp.php
Created December 19, 2012 23:58
Output buffer for large output to temporary file on disk (>2MB)
<?php
/*
* Output buffer for large output to temporary file on disk (>2MB)
*
* @link http://stackoverflow.com/questions/5446647/how-can-i-use-var-dump-output-buffering-without-memory-errors/
*/
/**
* Iterate over lines of a stream resource.
*
@hakre
hakre / schematest.php
Created December 13, 2012 18:57
Speeding up XML schema validations of a batch of XML files against the same XML schema (XSD)
<?php
/**
* @link http://stackoverflow.com/questions/13865149/speeding-up-xml-schema-validations-of-a-batch-of-xml-files-against-the-same-xml
*/
$mapping = [
'http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd' => 'schema/xhtml1-transitional.xsd',
'http://www.w3.org/2001/xml.xsd' => 'schema/xml.xsd',
];
@hakre
hakre / NoRewindLimitIterator.php
Created December 11, 2012 20:49
NoRewindLimitIterator
<?php
class NoRewindLimitIterator extends IteratorIterator
{
private $start, $count, $next;
public function __construct($it, $start, $count) {
parent::__construct($it);
$this->start = max(0, $start);
$this->count = max(0, $count);
@hakre
hakre / iconv-l.txt
Created December 2, 2012 12:35
Iconv List of Encodings
ANSI_X3.4-1968 ANSI_X3.4-1986 ASCII CP367 IBM367 ISO-IR-6 ISO646-US ISO_646.IRV:1991 US US-ASCII CSASCII
UTF-8
ISO-10646-UCS-2 UCS-2 CSUNICODE
UCS-2BE UNICODE-1-1 UNICODEBIG CSUNICODE11
UCS-2LE UNICODELITTLE
ISO-10646-UCS-4 UCS-4 CSUCS4
UCS-4BE
UCS-4LE
UTF-16
UTF-16BE
@hakre
hakre / csv-keyed-spl.php
Created November 27, 2012 09:49
Decorate Iterators - CSV Data Example
<?php
/**
* @link http://stackoverflow.com/q/10181054/367456
*/
/**
* Extending from a TraversableDecorator allows to decorate (change) the Iterator
* being Traversed without changing the object.
*/