League\CommonMark\Util\Html5Entities::decodeEntity PHP Method

decodeEntity() public static method

public static decodeEntity ( string $entity ) : string
$entity string
return string
    public static function decodeEntity($entity)
    {
        if (substr($entity, -1) !== ';') {
            return $entity;
        }
        if (substr($entity, 0, 2) === '&#') {
            if (strtolower(substr($entity, 2, 1)) === 'x') {
                return self::fromHex(substr($entity, 3, -1));
            } else {
                return self::fromDecimal(substr($entity, 2, -1));
            }
        }
        $name = substr($entity, 1, -1);
        if (isset(self::$entitiesByName[$name])) {
            return self::$entitiesByName[$name];
        }
        return $entity;
    }

Usage Example

 /**
  * @param ContextInterface $context
  * @param InlineParserContext $inlineContext
  *
  * @return bool
  */
 public function parse(ContextInterface $context, InlineParserContext $inlineContext)
 {
     if ($m = $inlineContext->getCursor()->match(RegexHelper::REGEX_ENTITY)) {
         $inlineContext->getInlines()->add(new Text(Html5Entities::decodeEntity($m)));
         return true;
     }
     return false;
 }
All Usage Examples Of League\CommonMark\Util\Html5Entities::decodeEntity