arse/includes/form/modifiers.inc.php
Emmanuel BENOîT 871d28cd16 Importing bits and pieces
This is the initial import based on a few files I had around.
2012-02-05 12:56:54 +01:00

26 lines
453 B
PHP

<?php
class Modifier_TrimString
implements FieldModifier
{
private $removeDuplicateSpaces;
public function __construct( $removeDuplicateSpaces = true )
{
$this->removeDuplicateSpaces = $removeDuplicateSpaces;
}
public function replace( $value )
{
if ( $value === null ) {
return '';
}
$value = trim( $value );
if ( $this->removeDuplicateSpaces ) {
$value = preg_replace( '/\s\s+/' , ' ' , $value );
}
return $value;
}
}