Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CodePointString.php

function CodePointString::replace

Overrides AbstractString::replace

File

vendor/symfony/string/CodePointString.php, line 168

Class

CodePointString
Represents a string of Unicode code points encoded as UTF-8.

Namespace

Symfony\Component\String

Code

public function replace(string $from, string $to) : static {
    $str = clone $this;
    if ('' === $from || !preg_match('//u', $from)) {
        return $str;
    }
    if ('' !== $to && !preg_match('//u', $to)) {
        throw new InvalidArgumentException('Invalid UTF-8 string.');
    }
    if ($this->ignoreCase) {
        $str->string = implode($to, preg_split('{' . preg_quote($from) . '}iuD', $this->string));
    }
    else {
        $str->string = str_replace($from, $to, $this->string);
    }
    return $str;
}
RSS feed
Powered by Drupal