Texy\Regexp::replace PHP Method

replace() public static method

Perform a regular expression search and replace.
public static replace ( $subject, $pattern, $replacement = NULL ) : string
return string
    public static function replace($subject, $pattern, $replacement = NULL)
    {
        if (is_object($replacement) || is_array($replacement)) {
            $res = preg_replace_callback($pattern, $replacement, $subject);
            if ($res === NULL && preg_last_error()) {
                // run-time error
                trigger_error(@self::$messages[preg_last_error()], E_USER_WARNING);
            }
            return $res;
        } elseif ($replacement === NULL && is_array($pattern)) {
            $replacement = array_values($pattern);
            $pattern = array_keys($pattern);
        }
        $res = preg_replace($pattern, $replacement, $subject);
        if (preg_last_error()) {
            // run-time error
            trigger_error(@self::$messages[preg_last_error()], E_USER_WARNING);
        }
        return $res;
    }

Usage Example

Esempio n. 1
0
 public function postLine($text, $preserveSpaces = FALSE)
 {
     if (!$preserveSpaces) {
         $text = Texy\Regexp::replace($text, '# {2,}#', ' ');
     }
     return Texy\Regexp::replace($text, $this->pattern);
 }
All Usage Examples Of Texy\Regexp::replace