Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
programming

Thomas Weinert ThomasWeinert

💻
programming
View GitHub Profile
@ThomasWeinert
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
:LINK_VERSION
set PHP_VERSION=%1
set PHP_BASE_PATH=%~dp0
set "PHP_BINARY=%~dp0PHP_%PHP_VERSION%\php"
@ThomasWeinert
ThomasWeinert / xml-namespace-read.php
Created Nov 1, 2019
How to read XML with namespaces
View xml-namespace-read.php
<?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>');
View build-with-import.md

libary.xml

<project name="buildlibrary" default="hello">
  <target name="hello" hidden="yes">
    <echo message="Hello World!"/>
  </target>
</project>
View svg spinner
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="150" height="100">
<defs>
<filter id="b">
<feGaussianBlur stdDeviation="12"/>
</filter>
<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'/>
View keybase.md

Keybase proof

I hereby claim:

  • I am thomasweinert on github.
  • I am thomasweinert (https://keybase.io/thomasweinert) on keybase.
  • I have a public key ASBwbCBQ_ZVJ6zqKiD0Bb3WkLLf4Rz6VObXll9dMYggZXwo

To claim this, I am signing this object:

@ThomasWeinert
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
<?php
$xml = file_get_contents('php://stdin');
class MyXpath extends DOMXpath {
private static $_context = null;
public function __construct($document) {
parent::__construct($document);
View simplexml-addchild.php
<?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);
$node->appendChild($node->ownerDocument->createTextNode($value));
}
@ThomasWeinert
ThomasWeinert / hhvm_getter.php
Created Feb 12, 2015
Test if HHVM still uses __get/__set or has implemented the properties.
View hhvm_getter.php
<?php
$xml = <<<'XML'
<root attribute="42"></root>
XML;
$dom = new DOMDocument();
$dom->preserveWhiteSpace = FALSE;
$dom->loadXml($xml);
@ThomasWeinert
ThomasWeinert / domtest.php
Created Feb 11, 2015
FluentDOM\Document - extends DOMDocument
View domtest.php
<?php
require_once(__DIR__.'/vendor/autoload.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;