PHPePub\Helpers\StringHelper::decodeHtmlEntities PHP Method

decodeHtmlEntities() public static method

Remove all non essential html tags and entities.
public static decodeHtmlEntities ( string $string ) : string
$string string
return string with the stripped entities.
    public static function decodeHtmlEntities($string)
    {
        $string = preg_replace('~\\s*<br\\s*/*\\s*>\\s*~i', "\n", $string);
        $string = preg_replace('~\\s*</(p|div)\\s*>\\s*~i', "\n\n", $string);
        $string = preg_replace('~<[^>]*>~', '', $string);
        $string = strtr($string, StaticData::$htmlEntities);
        $string = str_replace('&', '&amp;', $string);
        $string = str_replace('&amp;amp;', '&amp;', $string);
        $string = preg_replace('~&amp;(#x*[a-fA-F0-9]+;)~', '&\\1', $string);
        $string = str_replace('<', '&lt;', $string);
        $string = str_replace('>', '&gt;', $string);
        return $string;
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $cssFileName
  * @param string $title
  *
  * @return string
  */
 function buildEPub3TOC($cssFileName = null, $title = "Table of Contents")
 {
     $this->ncx->referencesOrder = $this->referencesOrder;
     $this->ncx->setDocTitle(StringHelper::decodeHtmlEntities($this->title));
     return $this->ncx->finalizeEPub3($title, $cssFileName);
 }