Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Class SimpleXMLElementXpathObject
*
* Object properties are mapped to Xpath queries
*/
class SimpleXMLElementXpathObject implements IteratorAggregate, JsonSerializable
{
private $anchor;
private $props;
@hakre
hakre / output-beautified.xml
Last active January 20, 2016 13:54
Expedia PHP SimpleXML API Code Example - See as well http://stackoverflow.com/a/16568432/367456
<?xml version="1.0"?>
<ns2:HotelListResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/">
<?xml-stylesheet type="text/xsl" href="css/stile.xsl"?>
<customerSessionId>...
<!-- Link: http://stackoverflow.com/questions/12960211/how-to-filter-a-select-nodeset-with-a-php-function -->
<p>
<name>Name-1</name>
<name>Name-2</name>
<name>Name-3</name>
<name>Name-4</name>
</p>
<?php
error_reporting(E_ALL);
function xrange($start, $end, $step = 1) {
for ($i = $start; $i < $end; $i += $step) {
yield $i;
}
}
@hakre
hakre / question_smallest_range_in_sorted_lists.php
Last active December 16, 2015 06:58
You have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists. <http://chat.stackoverflow.com/transcript/message/8874494#8874494>
<?php
/*
* You have k lists of sorted integers. Find the smallest range that includes at least one number
* from each of the k lists.
*
* @link http://chat.stackoverflow.com/transcript/message/8874494#8874494
*/
$lists = [
[1, 2, 20, 39],
@hakre
hakre / preg_replace_callback_offset.php
Last active December 6, 2017 08:50
preg_replace_callback_offset() - preg_replace_callback() with offset capturing.
<?php
/**
* preg_replace_callback_offset()
*
* preg_replace_callback() with offset capturing.
*
* Usage:
*
* Works exactly like preg_replace_callback() but differs in passing the matches to the callback function.
* Matches are as if using preg_match() with the PREG_OFFSET_CAPTURE flag:
@hakre
hakre / Micro.php
Created March 20, 2013 01:50
schema.org microdata reading PHP class for use with DOMDocument or SimpleXML.
<?php
/*
* Micro Class For Micro Data
* Powered by libxml
*
* @author hakre <http://hakre.wordpress.com/>
* @version 0.7.1
*/
/**
@hakre
hakre / XMLRecoder.php
Last active December 15, 2015 03:29
Inspect and modify character encoding of an XML document based on XML Declaration and BOM.
<?php
/**
* XMLRecoder
*
* Utility class to extract and change encoding information stored
* inside an XML declaration and to recode an XML string
*
* Requires: iconv for string recoding (iconv is available by default)
* <http://php.net/iconv>
*
@hakre
hakre / CachedPDOStatement.php
Created March 13, 2013 13:35
CachtingIterator for a PDOStatement with support for multiple iterations.
<?php
/**
* Class CachedPDOStatement
*
* CachingIterator for a PDOStatement
*/
class CachedPDOStatement extends CachingIterator
{
private $index;
@hakre
hakre / README.md
Last active August 18, 2022 12:57
Iterators for PHP XMLReader for ease of parsing

Iterators for PHP XMLReader for Ease of Parsing

Change Log:

  • 0.1.12 maintenance release with fixes.

  • 0.1.11 maintenance release with fixes. added XMLReader::CDATA and XMLReader::WHITESPACE node support for XMLWritingIteration. added