note 116810 modified in function.preg-replace-callback by sobak
| From: | sobak@php.net | Date: | Sat, 07 Mar 2015 07:54:32 +0000 |
| Subject: | note 116810 modified in function.preg-replace-callback by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201881@lists.php.net to get a copy of this message | ||
<?php
// Nice little function that convert a string to uppercase by keeping the HTMLentities intact.
public static function strtoupper_entities($str) {
$patternMajEntities =
'/(\&([A-Z])(ACUTE|CEDIL|CARON|CIRC|GRAVE|ORN|RING|SLASH|TH|TILDE|UML)\;)+/';
$str = preg_replace_callback ($patternMajEntities,
function ($matches) {
return "&" . $matches[2] . strtolower($matches[3]) . ";";
}, strtoupper($str));
return $str;
}
--was--
// Nice little function that convert a string to uppercase by keeping the HTMLentities intact.
public static function strtoupper_entities($str) {
$patternMajEntities =
'/(\&([A-Z])(ACUTE|CEDIL|CARON|CIRC|GRAVE|ORN|RING|SLASH|TH|TILDE|UML)\;)+/';
$str = preg_replace_callback ($patternMajEntities,
function ($matches) {
return "&" . $matches[2] . strtolower($matches[3]) . ";";
}, strtoupper($str));
return $str;
}
http://php.net/manual/en/function.preg-replace-callback.php