Encode unwanted characters in PHP

Description

The following code shows how to encode unwanted characters.

Example


/*from  ww w  .j a va2 s .c  o m*/
<?php
    $var="<b>XML Griffin<b>";

    var_dump(filter_var($var, FILTER_SANITIZE_STRING));

/*
  Possible options and flags:

  FILTER_FLAG_NO_ENCODE_QUOTES - This flag does not encode quotes
  FILTER_FLAG_STRIP_LOW - Strip characters with ASCII value below 32
  FILTER_FLAG_STRIP_HIGH - Strip characters with ASCII value above 127
  FILTER_FLAG_ENCODE_LOW - Encode characters with ASCII value below 32
  FILTER_FLAG_ENCODE_HIGH - Encode characters with ASCII value above 127
  FILTER_FLAG_ENCODE_AMP - Encode the & character to &amp;

*/

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone