{"id":301,"date":"2014-01-09T12:17:49","date_gmt":"2014-01-09T17:17:49","guid":{"rendered":"http:\/\/www.popmartian.com\/tipsntricks\/?p=301"},"modified":"2014-01-09T12:17:49","modified_gmt":"2014-01-09T17:17:49","slug":"how-to-use-multiple-filter-flags-in-php-filter-functions","status":"publish","type":"post","link":"https:\/\/www.popmartian.com\/tipsntricks\/2014\/01\/09\/how-to-use-multiple-filter-flags-in-php-filter-functions\/","title":{"rendered":"HOW TO Use Multiple Filter Flags in PHP Filter Functions"},"content":{"rendered":"<p>Using multiple filter flags in PHP is easy, but the documentation does not explain it well.<\/p>\n<p>The Filter capabilities in PHP 5.3 and above are very powerful and save a ton of effort, but the passing of flags to various filter functions is described minimally as a &#8220;bitwise disjunction of flags&#8221;.  This means you need to pass a bitwise conjunction of flags.<\/p>\n<p>Here&#8217;s the english translation:<br \/>\n<code>Pass a pipe-separated list of flags.<\/code><\/p>\n<p>That&#8217;s it.  You need to use the logical &#8216;OR&#8217; to create a parameter the parser will understand.<\/p>\n<p>If you want to use filter_var() to sanitize $string with FILTER_SANITIZE_STRING and pass in FILTER_FLAG_STRIP_HIGH and FILTER_FLAG_STRIP_LOW, just call it like this:<\/p>\n<p><code>$string = filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);<\/code><\/p>\n<p>That&#8217;s it.  Nothing magical.<\/p>\n<p>The same goes for passing a flags field in an options array in the case of using callbacks.  Here is an extended version of the example from php.net:<\/p>\n<p><code>$var = filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS,<br \/>\n                  array('flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH));<\/code><\/p>\n<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Using multiple filter flags in PHP is easy, but the documentation does not explain it well. The Filter capabilities in PHP 5.3 and above are very powerful and save a ton of effort, but the passing of flags to various &hellip; <a href=\"https:\/\/www.popmartian.com\/tipsntricks\/2014\/01\/09\/how-to-use-multiple-filter-flags-in-php-filter-functions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,11,9],"tags":[],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-how-to-do-stuff","category-php","category-programming"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":4,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/301\/revisions\/305"}],"wp:attachment":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}