$sanitizer->entitiesMarkdown() method

Entity encode while translating some markdown tags to HTML equivalents

If you specify boolean TRUE for the $options argument, full markdown is applied. Otherwise, only basic markdown allowed, as outlined in the examples.

The primary reason to use this over full-on Markdown is that it has less overhead and is faster then full-blown Markdown, for when you don't need it. It's also safer for text coming from user input since it doesn't allow any other HTML. But if you just want full markdown, then specify TRUE for the $options argument.

Basic allowed markdown currently includes:

  • **strong**
  • *emphasis*
  • [anchor-text](url)
  • ~~strikethrough~~
  • code surrounded by backticks

Example

// basic markdown
echo $sanitizer->entitiesMarkdown($str);

// full markdown
echo $sanitizer->entitiesMarkdown($str, true); 

Usage

// basic usage
$string = $sanitizer->entitiesMarkdown(string $str);

// usage with all arguments
$string = $sanitizer->entitiesMarkdown(string $str, $options = []);

Arguments

NameType(s)Description
strstring

String to apply markdown to

options (optional)array, bool, int

Options include the following, or specify boolean TRUE to apply full markdown.

  • fullMarkdown (bool): Use full markdown rather than basic? (default=false) when true, most options no longer apply. Note: A markdown flavor integer may also be supplied for the fullMarkdown option.
  • flags (int): PHP htmlentities() flags. Default is ENT_QUOTES.
  • encoding (string): PHP encoding type. Default is 'UTF-8'.
  • doubleEncode (bool): Whether to double encode (if already encoded). Default is true.
  • allow (array): Only markdown that translates to these tags will be allowed. Default is most inline HTML tags.
  • disallow (array): Specified tags (in the default allow list) that won't be allowed. Default=[] empty array. (Note: The 'disallow' is an alternative to the default 'allow'. No point in using them both.)
  • linkMarkup (string): Markup to use for links. Default=<a href="{url}" rel="nofollow" target="_blank">{text}</a>.
  • allowBrackets (bool): Allow some inline-level bracket tags, i.e. [span.detail]text[/span] ? (default=false)

Return value

string

Formatted with a flavor of markdown


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.125

Twitter updates

  • New post: This week we take a look at what’s in ProcessWire 3.0.126 which focuses largely on resolving issue reports, but also includes a handy new Page if() method— More
    15 February 2019
  • New post: ProcessWire 3.0.125 has several useful new Sanitizer methods & options, plus new ways to access them directly from the Input API variable. This makes handling user input even easier than before. Plus updates to our i18n functions & API docs— More
    25 January 2019
  • New post: In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124— More
    11 January 2019

Latest news

  • ProcessWire Weekly #249
    In the 249th issue of ProcessWire Weekly we're going to walk you through the latest core updates (ProcessWire 3.0.126), introduce a new third party module called Page Access Releasetime, and pick a new site of the week. Read on!
    Weekly.pw / 16 February 2019
  • ProcessWire 3.0.126 core updates
    This week we take a look at what’s in ProcessWire 3.0.126 which focuses largely on resolving issue reports, but also includes a handy new $page->if() method. 
    Blog / 15 February 2019
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer