/** * @param string $str * @param string $element * * @return string */ private function convertElement($str, $element) { $options = $this->getOptionsForElement($element); if (!$options) { return $str; } if (isset($options['case']) && $options['case'] != self::OPTION_NONE) { $mode = self::$caseModeMapping[$options['case']]; // string can contain HTML tags $chunks = preg_split('/(<[^>]*>)/', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); // convert only the text between HTML tags foreach ($chunks as $i => &$chunk) { if ($chunk[0] !== '<') { $chunk = UTF8::html_entity_decode($str); $chunk = mb_convert_case($chunk, $mode, 'UTF-8'); $chunk = htmlspecialchars_decode($chunk, ENT_QUOTES); } } $str = implode($chunks); if ($options['case'] == self::OPTION_UCFIRST) { $str = UTF8::ucfirst($str); } } if (isset($options['replace']) && $options['replace']) { if (isset($options['replace'][2])) { $delimiter = $options['replace'][2]; } else { $delimiter = '@'; } $str = preg_replace($delimiter . $options['replace'][0] . $delimiter, $options['replace'][1], $str); } if (isset($options['prepend']) && $options['prepend']) { $str = $options['prepend'] . $str; } if (isset($options['append']) && $options['append']) { $str .= $options['append']; } return $str; }