Skip to content

Instantly share code, notes, and snippets.

@chrif
chrif / NumberToStringTransformer.php
Created August 21, 2012 02:57 — forked from fain182/gist:3394880
Workaround for Issue #2059 in Symfony 2.0
<?php
namespace Acme\HelloBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* A simple number transformer that allows either comma or dot as decimal separator.
*
@chrif
chrif / xpath_escape.php
Created February 10, 2012 02:15 — forked from iaindooley/xpath_escape.php
Function to escape single and double quotes in XPath queries using PHP
<?php
function xpathEscape($query, $default_delim = '"')
{
if (strpos($query, $default_delim) === false)
return $default_delim . $query . $default_delim;
preg_match_all("#(?:('+)|[^']+)#", $query, $matches);
list($parts, $apos) = $matches;
foreach ($parts as $i => &$part) {
$delim = $apos[$i] ? '"' : "'";
$part = $delim . $part . $delim;