Skip to content

Instantly share code, notes, and snippets.

Avatar

hakre hakre

View GitHub Profile
@hakre
hakre / iteration-and-recursive-iteration.php
Created Sep 2, 2012
Iteration and Recursive Iteration Examples Code
View iteration-and-recursive-iteration.php
<?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 / README.md
Last active Sep 18, 2020
Iterators for PHP XMLReader for ease of parsing
View README.md

Iterators for PHP XMLReader for ease of parsing

Change Log:

  • 0.1.10 maintenance release with fixes.

  • 0.1.9 maintenance release with fixes. added XMLReaderNode::expand().

  • 0.1.8 maintenance release with fixes.

@hakre
hakre / dl-file.php
Created Jan 2, 2012
Wordpress login to download uploaded files
View dl-file.php
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+
@hakre
hakre / gist:826061
Created Feb 14, 2011
WP_Query_Columns - Columns for the loop. - http://wordpress.stackexchange.com/q/9308/178
View gist:826061
<?php
/**
* get_columns_array
*
* Columns for the loop, single function interface (limited)
*
* Copyright (c) 2011 hakre <http://hakre.wordpress.com/>, some rights reserved
*
* USAGE:
@hakre
hakre / imap-attachment.php
Created Apr 11, 2012
Save attachments from imap messages to disk.
View imap-attachment.php
<?php
/**
* imap-attachment.php
*
* @author hakre <hakre.wordpress.com>
* @link http://stackoverflow.com/questions/9974334/how-to-download-mails-attachment-to-a-specific-folder-using-imap-and-php
*/
/**
* Utility Class
@hakre
hakre / iconv-l.txt
Created Dec 2, 2012
Iconv List of Encodings
View iconv-l.txt
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 / attacks-xml.php
Created Apr 18, 2012
PHP DOMDocument/libxml billion laughs / quadratic blowup
View attacks-xml.php
<?php
/**
* @link http://stackoverflow.com/q/10212752/367456
* @link http://msdn.microsoft.com/en-us/magazine/ee335713.aspx
*/
$file = 'billion-laughs-2.xml';
$file = 'quadratic-blowup-2.xml';
printf("Mem: %s (Peak: %s)\n", number_format(memory_get_usage(), 0, '', ' '), number_format(memory_get_peak_usage(), 0, '', ' '));
View dateperiod-iterator.php
<?php
/*
* Get all 52 weeks of the year and work days given the first day of the January of current year
* @link http://stackoverflow.com/a/14147613/367456
* @author hakre <http://hakre.wordpress.com/credits>
*/
/**
* Filter a DatePeriod by year
*/
@hakre
hakre / simplexml-import.php
Created Feb 12, 2013
In SimpleXML, how can I add an existing SimpleXMLElement as a child element?
View simplexml-import.php
<?php
/**
* In SimpleXML, how can I add an existing SimpleXMLElement as a child element?
*
* @link http://stackoverflow.com/q/767327/367456
* @link http://eval.in/9568
* @link http://3v4l.org/1sI05
*/
/**
@hakre
hakre / CachedPDOStatement.php
Created Mar 13, 2013
CachtingIterator for a PDOStatement with support for multiple iterations.
View CachedPDOStatement.php
<?php
/**
* Class CachedPDOStatement
*
* CachingIterator for a PDOStatement
*/
class CachedPDOStatement extends CachingIterator
{
private $index;
You can’t perform that action at this time.