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.
<?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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment