How to clean a string using php code

in PHP Code / 1 Comment

The following script will be clean a string, this code fill helpful when going send a string to url that means using get method using php.

How to clean a string using PHP code by Anil Kumar Panigrahi

How to clean a string using PHP code by Anil Kumar Panigrahi

PHP Code

function CleaningAString($string)
  {
      $string = strtolower($string);
      // Replace other special chars
      $specialCharacters = array(
     '#' => 'sharp',
     '$' => 'dollar',
     '%' => 'percent',
     '&' => 'and',
     '@' => 'at',
     '€' => 'euro',
     '+' => 'plus',
     '=' => 'equals to',
     '§' => 'paragraph',
      );
     while (list($character, $replacement) = each($specialCharacters))  {
          $string = str_replace($character, '-' . $replacement . '-', $string);
      }
      return $string;
  }

This code will replace the all special characters to string using following this php function.

I hope that it will be helpful.

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Discussion 1 Comment

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>