Skip to content

Instantly share code, notes, and snippets.


Thomas Weinert ThomasWeinert

View GitHub Profile
ThomasWeinert / php-version.bat
Created Mar 13, 2021
Allow for switch between multiple PHP versions. Expects the PHP version to be in subdirectories `PHP_%VERSION%` (PHP_8.0.4).
View php-version.bat
@echo off & setlocal enabledelayedexpansion
IF "%~1"=="" GOTO Help
IF "%~1"=="list" GOTO ListVersion
IF "%~1"=="bat" GOTO CreateBatchFiles
set PHP_BASE_PATH=%~dp0
ThomasWeinert / xml-namespace-read.php
Created Nov 1, 2019
How to read XML with namespaces
View xml-namespace-read.php
// define the namespace URI as a constant
// this is often an URL but it does not have to be one
// in existing XMLs look for the "xmlns/xmlns:*" attributes
const XMLNS_EXAMPLE = 'urn:example-namespace';
// load a really basic XML with the example namespace
$document = new DOMDocument();
$document->loadXML('<f:foo xmlns:f="urn:example-namespace">content</f:foo>');


<project name="buildlibrary" default="hello">
  <target name="hello" hidden="yes">
    <echo message="Hello World!"/>
View svg spinner
<?xml version="1.0"?>
<svg xmlns="" version="1.1" width="150" height="100">
<filter id="b">
<feGaussianBlur stdDeviation="12"/>
<linearGradient id='spinner'>
<stop stop-color='rgba(255, 255, 255, 0)'/>
<stop offset='0.2' stop-color='rgba(255, 255, 255, 0)'/>
<stop offset='0.5' stop-color='#fff'/>

Keybase proof

I hereby claim:

  • I am thomasweinert on github.
  • I am thomasweinert ( on keybase.
  • I have a public key ASBwbCBQ_ZVJ6zqKiD0Bb3WkLLf4Rz6VObXll9dMYggZXwo

To claim this, I am signing this object:

ThomasWeinert / xpath-context.php
Created Aug 24, 2015
Using a callback to fetch the current context in an xpath expression, this might allow to implement the CSS selector `:scope`
View xpath-context.php
$xml = file_get_contents('php://stdin');
class MyXpath extends DOMXpath {
private static $_context = null;
public function __construct($document) {
View simplexml-addchild.php
class MySimpleXMLElement extends SimpleXMLElement {
public function addChild($name, $value = null, $namespace = null) {
$result = parent::addChild($name, null, $namespace);
if (isset($value)) {
$node = dom_import_simplexml($result);
ThomasWeinert / hhvm_getter.php
Created Feb 12, 2015
Test if HHVM still uses __get/__set or has implemented the properties.
View hhvm_getter.php
$xml = <<<'XML'
<root attribute="42"></root>
$dom = new DOMDocument();
$dom->preserveWhiteSpace = FALSE;
ThomasWeinert / domtest.php
Created Feb 11, 2015
FluentDOM\Document - extends DOMDocument
View domtest.php
function test_fd() {
$html = file_get_contents(__DIR__.'/data.html');
$html = '<?xml encoding="utf-8"?>'.$html;
$dom = FluentDOM::load($html, 'text/html');
$r = array();
View XMLCreator.js
var XMLCreatorFactory = function(dom, resolver) {
if (dom === true) {
dom = document.implementation.createDocument('', '', null);
} else if (!(dom instanceof Document)) {
dom = document;
var lookupNamespaceURI;
if (resolver instanceof Function && !resolver.lookupNamespaceURI instanceof Function) {
lookupNamespaceURI = resolver;