JBZoo\Utils\Str::htmlEnt PHP 메소드

htmlEnt() 공개 정적인 메소드

Convert >, <, ', " and & to html entities, but preserves entities that are already encoded.
public static htmlEnt ( string $string, boolean $encodedEntities = false ) : string
$string string The text to be converted
$encodedEntities boolean
리턴 string
    public static function htmlEnt($string, $encodedEntities = false)
    {
        if ($encodedEntities) {
            // @codeCoverageIgnoreStart
            if (defined('HHVM_VERSION')) {
                $transTable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
            } else {
                /** @noinspection PhpMethodParametersCountMismatchInspection */
                $transTable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, self::$encoding);
            }
            // @codeCoverageIgnoreEnd
            $transTable[chr(38)] = '&';
            $regExp = '/&(?![A-Za-z]{0,4}\\w{2,3};|#[0-9]{2,3};)/';
            return preg_replace($regExp, '&amp;', strtr($string, $transTable));
        }
        return htmlentities($string, ENT_QUOTES, self::$encoding);
    }

Usage Example

예제 #1
0
파일: Filter.php 프로젝트: jbzoo/utils
 /**
  * @param $string
  * @return string
  */
 public static function html($string)
 {
     return Str::htmlEnt($string);
 }
All Usage Examples Of JBZoo\Utils\Str::htmlEnt