Posted By

fackz on 05/29/09


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Strip non alphanumeric characters from a string with php

 / Published in: PHP

You may need it when you code an user authentication script and want to prevent the user to hack it with ascii injection.

$new_string content will be: Hi I am a string and I need to be stripped without any coma or stop.

  1. <?php
  2. $string_to_be_stripped = "Hi, I am a string and I need to be stripped...";
  3. $new_string = ereg_replace("[^A-Za-z0-9]", "", $string_to_be_stripped );
  4. ?>

Report this snippet  

You need to login to post a comment.