Example #1
0
 /**
  * Find and replace macros in the given XML section.
  *
  * @param string $documentPartXML
  * @param string $search
  * @param string $replace
  * @param integer $limit
  *
  * @return string
  */
 protected function setValueForPart($documentPartXML, $search, $replace, $limit)
 {
     if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
         $search = '${' . $search . '}';
     }
     if (!StringElement::isUTF8($replace)) {
         $replace = utf8_encode($replace);
     }
     // Note: we can't use the same function for both cases here, because of performance considerations.
     if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
         return str_replace($search, $replace, $documentPartXML);
     } else {
         $regExpDelim = '/';
         $escapedSearch = preg_quote($search, $regExpDelim);
         return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit);
     }
 }
Example #2
0
 /**
  * Is UTF8
  */
 public function testIsUTF8()
 {
     $this->assertTrue(StringElement::isUTF8(''));
     $this->assertTrue(StringElement::isUTF8('éééé'));
     $this->assertFalse(StringElement::isUTF8(utf8_decode('éééé')));
 }