Skip to content

Instantly share code, notes, and snippets.

View dschnare's full-sized avatar

Darren Schnare dschnare

View GitHub Profile
@matb33
matb33 / gist:1229317
Created September 20, 2011 14:57
Inline variable parsing function with multibyte support
<?php
// parseInlineVariables takes a multibyte string "stringToParse" and parses for $variable style
// variables to swap with the value found in the "variables" associative array. It also supports
// better matching with curly braces surrounding the variable, such as {$variable}. Spaces
// within the curly braces are OK: { $variable } works too.
// Adapt this function to your particular framework (put it in a class, keep it global, etc)
function parseInlineVariables( $stringToParse, Array $variables )
{
@matb33
matb33 / DOMDocumentExtended.php
Last active May 23, 2020 21:26
DOMDocument->saveJSON()
<?php
// saveJSON: XML to JSON conversion/transformation
// The saveJSON method is implemented as a method of the example DOMDocumentExtended class, which
// extends DOMDocument. It will transform the currently loaded DOM into JSON using XSLT. Since
// there isn't a reliable automatic way of detecting if certain siblings nodes should be
// represented as arrays or not, a "forceArray" parameter can be passed to the saveJSON method.
// It should be noted that the forceArray functionality doesn't recognize namespaces. This is
// an easy enough fix, I just didn't need it at the time of writing (look for local-name() and