Skip to content

Instantly share code, notes, and snippets.

@sasezaki
Created June 6, 2012 11:49
Show Gist options
  • Save sasezaki/2881443 to your computer and use it in GitHub Desktop.
Save sasezaki/2881443 to your computer and use it in GitHub Desktop.
ZF2-170
<?php
require_once __DIR__.'/library/Zend/Loader/StandardAutoloader.php';
use Zend\Loader\StandardAutoloader;
use Zend\Filter\StringTrim;
$autoloader = new StandardAutoloader;
$autoloader->register();
class Before extends StringTrim
{
protected function _unicodeTrim($value, $charlist = '\\\\s')
{
$chars = preg_replace(
array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'),
array( '\\\\\\0', '\\', '\/' ),
$charlist
);
$pattern = '^[' . $chars . ']*|[' . $chars . ']*$';
return preg_replace("/$pattern/usSD", '', $value);
}
}
class After extends StringTrim
{
protected function _unicodeTrim($value, $charlist = '\\\\s')
{
$chars = preg_replace(
array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'),
array( '\\\\\\0', '\\', '\/' ),
$charlist
);
$pattern = '^[' . $chars . ']*|[' . $chars . ']*$';
return preg_replace("/$pattern/sSD", '', $value);
}
}
$filter = new Before();
$value = $filter->filter('あいうえお ');
var_dump($value); // string(15) "あいうえお"
$filter = new After();
$value = $filter->filter('あいうえお ');
var_dump($value); // string(18) "あいうえお "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment