"Fossies" - the Fresh Open Source Software Archive

Member "smarty-3.1.34/libs/plugins/shared.escape_special_chars.php" (28 Feb 2019, 977 Bytes) of package /linux/www/smarty-3.1.34.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "shared.escape_special_chars.php": 3.1.32_vs_3.1.33.

    1 <?php
    2 /**
    3  * Smarty shared plugin
    4  *
    5  * @package    Smarty
    6  * @subpackage PluginsShared
    7  */
    8 /**
    9  * escape_special_chars common function
   10  * Function: smarty_function_escape_special_chars
   11  * Purpose:  used by other smarty functions to escape
   12  *           special chars except for already escaped ones
   13  *
   14  * @author Monte Ohrt <monte at ohrt dot com>
   15  *
   16  * @param string $string text that should by escaped
   17  *
   18  * @return string
   19  */
   20 function smarty_function_escape_special_chars($string)
   21 {
   22     if (!is_array($string)) {
   23         if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
   24             $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
   25         } else {
   26             $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
   27             $string = htmlspecialchars($string);
   28             $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
   29         }
   30     }
   31     return $string;
   32 }