Skip to content

Instantly share code, notes, and snippets.

@nowa75
Forked from joostvanveen/textile_filter.php
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save nowa75/c0d575d96ce6f2bacc9a to your computer and use it in GitHub Desktop.

Select an option

Save nowa75/c0d575d96ce6f2bacc9a to your computer and use it in GitHub Desktop.

Revisions

  1. Joost van Veen created this gist Mar 3, 2013.
    26 changes: 26 additions & 0 deletions textile_filter.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php

    /**
    * Filter input based on a whitelist. This filter strips out all characters that
    * are NOT:
    * - letters
    * - numbers
    * - Textile Markup special characters.
    *
    * Textile markup special characters are:
    * _-.*#;:|!"+%{}@
    *
    * This filter will also pass cyrillic characters, and characters like é and ë.
    *
    * Typical usage:
    * $string = '_ - . * # ; : | ! " + % { } @ abcdefgABCDEFG12345 éüртхцчшщъыэюьЁуфҐ ' . "\nAnd another line!";
    * echo textile_sanitize($string);
    *
    * @param string $string
    * @return string The sanitized string
    * @author Joost van Veen
    */
    function textile_sanitize($string){
    $whitelist = '/[^a-zA-Z0-9а-яА-ЯéüртхцчшщъыэюьЁуфҐ \.\*\+\\n|#;:!"%@{} _-]/';
    return preg_replace($whitelist, '', $string);
    }