Skip to content

Instantly share code, notes, and snippets.

@jonasbjork
Created March 3, 2011 10:23
Show Gist options
  • Save jonasbjork/852588 to your computer and use it in GitHub Desktop.
Save jonasbjork/852588 to your computer and use it in GitHub Desktop.
Snippet for removing illegal chars from a string.
<?php
// Remove illegal chars, replacing them with a dash (-)
$str = "abc är du här? eLLller ELLER kanske däår?";
$str = preg_replace('/[^0-9a-zA-Z]+/', '-', $str);
// results in -> "abc-r-du-h-r-eLLller-ELLER-kanske-d-r-"
echo $str.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment