Ignore:
Timestamp:
Aug 8, 2019 10:03:59 PM (5 years ago)
Author:
anonymous
Message:

Add unicode flag (/u) to preg_* patterns. Remove usage of create_function().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r690 r696  
    122122    $d = ob_get_contents();
    123123    ob_end_clean();
    124     return $serialize ? preg_replace('/\s+/m', ' ', $d) : $d;
     124    return $serialize ? preg_replace('/\s+/mu', ' ', $d) : $d;
    125125}
    126126
     
    154154        $output .= sprintf("%s%s\n", $indent_str, $var);
    155155    }
    156     return preg_replace(['/^[ \t]+$/', '/\n\n+/', '/^(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(\S )/m'], ['', "\n", '$1$1$2$2$3$3$4$4$5$5$6$6$7$7$8$8$9'], $output);
     156    return preg_replace(['/^[ \t]+$/u', '/\n\n+/u', '/^(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(\S )/mu'], ['', "\n", '$1$1$2$2$3$3$4$4$5$5$6$6$7$7$8$8$9'], $output);
    157157}
    158158
     
    189189
    190190    // Make converted ampersand entities into normal ampersands (they will be done manually later) to retain HTML entities.
    191     $search['retain_ampersand']     = '/&/';
     191    $search['retain_ampersand']     = '/&/u';
    192192    $replace['retain_ampersand']    = '&';
    193193
    194194    if ($preserve_html) {
    195195        // Convert characters that must remain non-entities for displaying HTML.
    196         $search['retain_left_angle']       = '/</';
     196        $search['retain_left_angle']       = '/</u';
    197197        $replace['retain_left_angle']      = '<';
    198198
    199         $search['retain_right_angle']      = '/&gt;/';
     199        $search['retain_right_angle']      = '/&gt;/u';
    200200        $replace['retain_right_angle']     = '>';
    201201
    202         $search['retain_single_quote']     = '/&#039;/';
     202        $search['retain_single_quote']     = '/&#039;/u';
    203203        $replace['retain_single_quote']    = "'";
    204204
    205         $search['retain_double_quote']     = '/&quot;/';
     205        $search['retain_double_quote']     = '/&quot;/u';
    206206        $replace['retain_double_quote']    = '"';
    207207    }
     
    309309            // If not truncating, or URL was not truncated.
    310310            // Remove http schemas, and any single trailing / to make the display URL.
    311             $display_url = preg_replace(['!^https?://!', '!^([^/]+)/$!'], ['', '$1'], $url);
     311            $display_url = preg_replace(['!^https?://!u', '!^([^/]+)/$!u'], ['', '$1'], $url);
    312312            return sprintf('<a href="%s">%s</a>', oTxt($absolute_url), $display_url);
    313313        } else {
    314314            // Truncated URL.
    315315            // Remove http schemas, and any single trailing / to make the display URL.
    316             $display_url = preg_replace(['!^https?://!', '!^([^/]+)/$!'], ['', '$1'], trim($truncated_url));
     316            $display_url = preg_replace(['!^https?://!u', '!^([^/]+)/$!u'], ['', '$1'], trim($truncated_url));
    317317            return sprintf('<a href="%s">%s%s</a>', oTxt($absolute_url), $display_url, $delim);
    318318        }
     
    337337    foreach ($words as $w) {
    338338        if ('' != trim($w)) {
    339             $search[] = '/\b(' . preg_quote($w) . ')\b/i';
     339            $search[] = '/\b(' . preg_quote($w) . ')\b/iu';
    340340            $replace[] = '<span class="' . $class . '">$1</span>';
    341341        }
     
    368368    default :
    369369        // Reduce all hex values slightly to avoid all white.
    370         array_walk($rgb, create_function('&$v', "\$v = dechex(round(hexdec(\$v) * $n));"));
     370        array_walk($rgb, function (&$v) use ($n) {
     371            $v = dechex(round(hexdec($v) * $n));
     372        });
    371373        break;
     374
    372375    case 2 :
    373376        foreach ($rgb as $i => $v) {
     
    411414function encodeEmail($email, $at=' at ', $dot=' dot ')
    412415{
    413     $search = array('/@/', '/\./');
     416    $search = array('/@/u', '/\./u');
    414417    $replace = array($at, $dot);
    415418    return preg_replace($search, $replace, $email);
     
    529532function URLSlug($str)
    530533{
    531     $slug = preg_replace(array('/\W+/u', '/^-+|-+$/'), array('-', ''), $str);
     534    $slug = preg_replace(array('/\W+/u', '/^-+|-+$/u'), array('-', ''), $str);
    532535    $slug = strtolower($slug);
    533536    return $slug;
     
    11381141function hash64($string, $length=18)
    11391142{
    1140     return mb_substr(preg_replace('/[^\w]/', '', base64_encode(hash('sha512', $string, true))), 0, $length);
     1143    return mb_substr(preg_replace('/[^\w]/u', '', base64_encode(hash('sha512', $string, true))), 0, $length);
    11411144}
    11421145
     
    11681171    switch ($app->getParam('signing_method')) {
    11691172    case 'sha512+base64':
    1170         return $val . '-' . mb_substr(preg_replace('/[^\w]/', '', base64_encode(hash('sha512', $val . $salt, true))), 0, $length);
     1173        return $val . '-' . mb_substr(preg_replace('/[^\w]/u', '', base64_encode(hash('sha512', $val . $salt, true))), 0, $length);
    11711174
    11721175    case 'md5':
     
    13951398function stripQuery($url)
    13961399{
    1397     return preg_replace('/[?#].*$/', '', $url);
     1400    return preg_replace('/[?#].*$/u', '', $url);
    13981401}
    13991402
     
    14051408function absoluteMe()
    14061409{
    1407     $safe_http_host = preg_replace('/[^a-z\d.:-]/', '', getenv('HTTP_HOST'));
     1410    $safe_http_host = preg_replace('/[^a-z\d.:-]/u', '', getenv('HTTP_HOST'));
    14081411    return sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host, getenv('REQUEST_URI'));
    14091412}
     
    14221425    // If one of the hostnames is an IP address, compare only the path of both.
    14231426    if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($current_url, PHP_URL_HOST)) || preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($referrer_url, PHP_URL_HOST))) {
    1424         $current_url = preg_replace('@^https?://[^/]+@', '', $current_url);
    1425         $referrer_url = preg_replace('@^https?://[^/]+@', '', $referrer_url);
     1427        $current_url = preg_replace('@^https?://[^/]+@u', '', $current_url);
     1428        $referrer_url = preg_replace('@^https?://[^/]+@u', '', $referrer_url);
    14261429    }
    14271430
Note: See TracChangeset for help on using the changeset viewer.